[R] writing a file using both cat() and paste()

Taka Matzmoto sell_mirage_ne at hotmail.com
Thu Feb 9 08:26:15 CET 2006


Hi R users

I like to create a ASCII type file using cat() and paste()

x <- round(runif(30),3)
cat("vector =( ", paste(x,sep=""), " )\n", file = "vector.dat",sep=",")

when I open vector.dat it was a long ugly file

vector =( 
,0.463,0.515,0.202,0.232,0.852,0.367,0.432,0.74,0.413,0.022,0.302,0.114,0.583,0.002,0.919,0.066,0.829,0.405,0.363,0.665,0.109,0.38,0.187,0.322,0.582,0.011,0.586,0.112,0.873,0.671, 
)

Also there was some problems right after opening parenthesis and before the 
closing parenthesis. Two comma were there

I like to to have a nice formatted one like below. That is, 5 random values 
per a line

vector =( 0.463,0.515,0.202,0.232,0.852,
0.367,0.432,0.74,0.413,0.022,
0.302,0.114,0.583,0.002,0.919,
0.066,0.829,0.405,0.363,0.665,
0.109,0.38,0.187,0.322,0.582,
0.011,0.586,0.112,0.873,0.671)

I would be appreciative if I get some help

TM




More information about the R-help mailing list