[R] Reading and writing data

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Apr 24 11:31:49 CEST 2001


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.07965693020656

See ?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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list