[R] R tools for large files

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 26 10:42:26 CEST 2003


On Tue, 26 Aug 2003 Ted.Harding at nessie.mcc.ac.uk wrote:

[...]

>   > X
>   [1] "1,4,5" "1,2,5" "5,1,2"
> 
> Now my Question:
> How do I convert X into the dataframe I would have got if I had read
> this output from a file instead of into the character vector X?
> 
> In other words, how to convert a vector of character strings, each
> of which is in comma-separated format as above, into the rows of
> a data-frame (or matrix, come to that)?

read.table() on a text connection.

> X <- c("1,4,5", "1,2,5", "5,1,2")
> read.table(textConnection(X), header=FALSE, sep=",")
  V1 V2 V3
1  1  4  5
2  1  2  5
3  5  1  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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list