[R] Reading complicated data file
james.holtman@convergys.com
james.holtman at convergys.com
Wed Sep 25 17:08:58 CEST 2002
You can read the file in as a character vector, 'grep' the ones you want
and then use 'textConnection'; e.g.,
> x.1 <- scan('/tempxx.txt', what='', sep='\n') # read file with '\n' as
separator
Read 6 items
> x.1
[1] "0 TITLE Title" " 0 XLEGEND Legend" "-1 LABEL x"
[4] "1 1 12" "1 2 30" "1 3 34"
> x.match <- x.1[grep("^1", x.1)] # match on leading '1'
> x.match
[1] "1 1 12" "1 2 30" "1 3 34"
> x.data <- read.table(textConnection(x.match)) # use textConnection to
'read' in the data
> x.data
V1 V2 V3
1 1 1 12
2 1 2 30
3 1 3 34
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
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._
--
"NOTICE: The information contained in this electronic mail transmission is
intended by Convergys Corporation for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential. If you have received this electronic
mail transmission in error, please delete it from your system without
copying or forwarding it, and notify the sender of the error by reply email
or by telephone (collect), so that the sender's address records can be
corrected."
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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