Hi All, Two quick questions. 1) I am using write.table to output data.frames to ascii files, e.g., test <- data.frame(rnorm(2)) write.table(test,file="output") "rnorm.2." "1" -0.718560808193286 "2" -1.07965693020656 Is it possible to output the data without the first column, i.e., "rnorm.2." -0.718560808193286 -1.07965693020656 2) Is there a simple way to read in data and skip lines, i.e., say skip every second line. I could use ``scan'' to read in the data and use a "for" loop to perform the skipping in R. However, I am wondering is there a one-step method. Thanks in advance, Dermot. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 24 Apr 2001, Dermot MacSweeney wrote:> Hi All, > > Two quick questions. > > 1) I am using write.table to output data.frames to ascii files, e.g., > > test <- data.frame(rnorm(2)) > write.table(test,file="output") > > "rnorm.2." > "1" -0.718560808193286 > "2" -1.07965693020656 > > Is it possible to output the data without the first column, i.e., > > "rnorm.2." > -0.718560808193286 > -1.07965693020656See ?write.table, especially the row.names argument (and set it to false).> 2) Is there a simple way to read in data and skip lines, i.e., say skip every > second line. I could use ``scan'' to read in the data and use a "for" loop to > perform the skipping in R. However, I am wondering is there a one-step method.Well, you could fake this by duplicating `what' and ignoring the extra cols. But, indexing is far easier. df <- read.table(...) df <- df[seq(1, length=nrow(df), by=2), ] -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dermot MacSweeney wrote:> > Hi All, > > Two quick questions. > > 1) I am using write.table to output data.frames to ascii files, e.g., > > test <- data.frame(rnorm(2)) > write.table(test,file="output") > > "rnorm.2." > "1" -0.718560808193286 > "2" -1.07965693020656 > > Is it possible to output the data without the first column, i.e., > > "rnorm.2." > -0.718560808193286 > -1.07965693020656It's in the help (?write.table): row.names either a logical value indicating whether the row names of x are to be written along with x, or a character vector of row names to be written.> 2) Is there a simple way to read in data and skip lines, i.e., say skip every > second line. I could use ``scan'' to read in the data and use a "for" loop to > perform the skipping in R. However, I am wondering is there a one-step method.I don't know a one step method. If the file is not too big, I would try reading in the whole data at first and through away not needed lines after that. Uwe -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._