[R] Reading complicated data file

Don MacQueen macq at llnl.gov
Wed Sep 25 16:27:27 CEST 2002


Something like

tmpdat <- scan('filename',what=list(id=0,col1='',col2=''))
use <- tmpdat$id==1
dat <- data.frame(x=as.numeric(tmpdat$col1[use]),
                   y=as.numeric(tmpdat$col2[use])

should get you a dataframe with two columns corresponding to the
second and third values from each row. (caveat: I haven't tested it. 
Check the documentation for scan regarding delimiters. Also, I'm 
assuming every row in your data is complete, with exactly three 
values.)

-Don

At 1:15 PM +0200 9/25/02, zlamal at ufi.fme.vutbr.cz wrote:
>Hi, I am new in R and I have problem with reading this data file
>
>0 TITLE Title
>  0 XLEGEND Legend
>-1 LABEL x
>1 1 12
>1 2 30
>1 3 34
>
>I want to read only lines starting with 1 (it indicates 1st plotting line)
>and create data set from second and third value on this row.
>
>Thank for advice
>Jakub Zlamal
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>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
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
--------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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