Skip to content
Back to formatted view

Raw Message

Message-ID: <8762gzdo9t.fsf@pobox.com>
Date: 2011-12-29T22:08:30Z
From: Tom Roche
Subject: [newbie] read row from file into vector
In-Reply-To: <E66794E69CFDE04D9A70842786030B93254985@PA-MBX03.na.tibco.com> <4EFCDF89.4030102@gmail.com>

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>