[R] reading row vectors from file

Ken Irving fnkci at uaf.edu
Thu Mar 3 22:22:53 CET 2005


Hi,

New to R, using version 2.0.1 (2004-11-15) on debian Linux (sid), kernel
2.6.8-2-686.

I have data in files with separate vectors on each row of the file,
e.g.,

    $ cat /tmp/stats
    freq,0,1,2,3,4,5,6,7,8,9,16,17,18,19,20,...
    noise,49,47,48,48,50,47,48,47,46,50,48,54,49,47,49,...
    signal,99,0,100,0,0,100,0,100,100,0,100,101,100,0,0,...
    pctrcv,5,0,5,0,0,5,0,5,11,0,5,5,5,0,0,...

I can transpose the data file (e.g., using an awk script), and then read
it using read.csv("tstats"),

    $ transpose /tmp/stats > /tmp/tstats
    $ cat /tmp/tstats
    freq,noise,signal,pctrcv
    0,49,99,5
    1,47,0,0
    2,48,100,5
    ...

but would prefer to import the line-oriented files directly. I've
drawn a blank after perusing help, documentation, google searches, etc.. 

Something like read.csv( "transpose stat |" ) might be nice, e.g., the
trailing pipe symbol invokes the argument as a shell pipeline, then
reads from stdin, but I'm just making this up...  Actually, this does
work:

    t <- read.csv( pipe("transpose stat1") )

but it does rely on an external transpose command. Is there a way to
read line-oriented vector files directly?

Thanks for any help or leads,
  
Ken

-- 
Ken Irving, Research Analyst, fnkci at uaf.edu
Water and Environmental Research Center
Institute of Northern Engineering
University of Alaska, Fairbanks




More information about the R-help mailing list