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"))) |
|||
print0(leftjust) |
|||
print0(rightjust) |
|||
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> |
||
Given a text file of many lines, where fields within a line |
|||
are delineated by a single 'dollar' character, write a program |
|||
that aligns each column of fields by ensuring that words in each |
|||
column are separated by at least one space. |
|||
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> |
||