[R] Reading complicated data file
John Fox
jfox at mcmaster.ca
Wed Sep 25 15:38:21 CEST 2002
Dear Jakub,
At 01:15 PM 9/25/2002 +0200, 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
If you know in advance where the data starts (i.e., that you need to skip
the first 3 rows), then you can read the data file with read.table in the
usual manner, but specifying the argument skip=3. This also supposes that
the lines to be skipped precede the data.
If the situation is more complicated -- e.g., you don't know in advance how
many lines to skip, or the data and non-data lines are intermixed -- then
there are several ways to proceed. One way would be to read the data in the
usual manner, and then to select rows for which the first column is 1; with
this approach, you would also have to handle converting columns two and
three to numeric. Alternatively, you could read the file line-by-line (see
?readLines).
I hope that this helps,
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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