Align columns: Difference between revisions

Content deleted Content added
→‎{{header|D}}: Actually, it seems to be incomplete
m →‎{{header|R}}: Fixed printing format
Line 981: Line 981:


=={{header|R}}==
=={{header|R}}==
{{incorrect|R|Alignment in the rightmost columns is wrong.}}
<lang R>
<lang R>
# Read in text
# Read in text
Line 1,004: Line 1,003:


# Print
# Print
print0 <- function(x) invisible(apply(x, 1, function(x) cat(x, "\n")))
noquote(leftjust)
print0(leftjust)
noquote(rightjust)
print0(rightjust)
noquote(centrejust)
print0(centrejust)
</lang>
</lang>
Right justified output shown.
Right justified output shown.
<div style="width:full;overflow:scroll"><pre>
<div style="width:full;overflow:scroll"><pre>
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
Given a text file of many lines, where fields within a line
[1,] Given a text file of many lines, where fields within a line
are delineated by a single 'dollar' character, write a program
[2,] are delineated by a single 'dollar' character, write a program
that aligns each column of fields by ensuring that words in each
[3,] that aligns each column of fields by ensuring that words in each
column are separated by at least one space.
[4,] column are separated by at least one space.
Further, allow for each word in a column to be either left
[5,] Further, allow for each word in a column to be either left
justified, right justified, or center justified within its column.
[6,] justified, right justified, or center justified within its column.
</pre></div>
</pre></div>