[R] [newbie] read row from file into vector

Tom Roche Tom_Roche at pobox.com
Thu Dec 29 23:08:30 CET 2011


Tom Roche 11-12-29 3:51 PM
>>> E.g., for a file such that

>>> $ head -n 2 ~/data/foo.csv | tail -n 1
>>> 5718,0.3,0.47,0,0,0,0,0,0,0,0,0.08,0.37,0,0,0.83,1.55,0,0,0,0,0,0,0,0,0,0.00,2.48,2.33,0.17,0,0,0,0,0,0,0.00,10.69,0.18,0,0,0,0

>>> I'd like to be able to populate a vector 'v' s.t.
>>> v[1]=5718, ... v[43]=0

Duncan Murdoch Thu, 29 Dec 2011 16:45:45 -0500
>> x <- read.csv("foo.csv", nrow=1)
>> x <- as.numeric(x[1,])  # convert to numeric vector

Aha!

William Dunlap Thu, 29 Dec 2011 21:49:13 +0000
> Look into connection objects, which let you open a file or other
> readable sort of thing and read it piece by piece. 

Will do, since what I plan to use R for (mostly) is manipulating very large netCDF files.

thanks, all! Tom Roche <Tom_Roche at pobox.com>



More information about the R-help mailing list