conv.fixed.width {reader} | R Documentation |
Pads each column to a common size so write.table() produces a fixed width format that looks nice
conv.fixed.width(dat)
dat |
data.frame or matrix |
returns dat with space padding as character
Nicholas Cooper nick.cooper@cimr.cam.ac.uk #' @author Nicholas Cooper nick.cooper@cimr.cam.ac.uk
orig.dir <- getwd(); setwd(tempdir()); # move to temporary dir df <- data.frame(ID=paste("ID",99:108,sep=""), scores=sample(150,10,TRUE)+30,age=sample(16,10,TRUE)) dff <- conv.fixed.width(df) write.table(df,file="notFW.txt",row.names=FALSE,col.names=FALSE,quote=FALSE) write.table(dff,file="isFW.txt",row.names=FALSE,col.names=FALSE,quote=FALSE) cat("Fixed-width:\n",paste(readLines("isFW.txt"),"\n"),sep="") cat("standard-format:\n",paste(readLines("notFW.txt"),"\n"),sep="") unlink(c("isFW.txt","notFW.txt")) setwd(orig.dir) # reset working dir to original