[R] Aligning ragged text columns
hadley wickham
h.wickham at gmail.com
Wed Jul 19 12:53:59 CEST 2006
> I find that things line up better in data.frames
That's a good idea, although I was hoping there would be something in
R to do it for me.
I have ended up with:
fwidth <- max(nchar(x[,1]))
descs <- strwrap(x[,2], width=width - fwidth - 5, simplify=FALSE)
output <- do.call(rbind, mapply(function(name, desc) {
cbind(c(name, rep("", length=length(desc)-1)), desc)
}, x[,1], descs))
cat(paste(format(output[,1]), output[,2], collapse="\n"), "\n")
Thanks,
Hadley
More information about the R-help
mailing list