conv.fixed.width: Convert a matrix or dataframe to fixed-width for nice file...

Description Usage Arguments Value Author(s) Examples

View source: R/reader.R

Description

Pads each column to a common size so write.table() produces a fixed width format that looks nice

Usage

1

Arguments

dat

data.frame or matrix

Value

returns dat with space padding as character

Author(s)

Nicholas Cooper nick.cooper@cimr.cam.ac.uk #' @author Nicholas Cooper nick.cooper@cimr.cam.ac.uk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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

Example output

Loading required package: NCmisc
Fixed-width:
 ID99  80  7 
ID100 150 13 
ID101  62 15 
ID102  94  8 
ID103  55  5 
ID104  83 11 
ID105  70 11 
ID106 177 16 
ID107  34  2 
ID108  49 11 
standard-format:
ID99 80 7 
ID100 150 13 
ID101 62 15 
ID102 94 8 
ID103 55 5 
ID104 83 11 
ID105 70 11 
ID106 177 16 
ID107 34 2 
ID108 49 11 

reader documentation built on May 2, 2019, 9:27 a.m.