[R] parsing a data file
Peter Wolf
s-plus at wiwi.uni-bielefeld.de
Tue Apr 27 12:14:59 CEST 2004
Hello Tamas,
here is a starting point for your file parsing problem:
@
<<*>>=
x1<-scan("t",what="")
print(x1)
x2<-paste(x1,collapse=" ")
print(x2)
x3<-strsplit(x2, "RECORD")[[1]]
print(x3)
@
output-start
[1] "BEGIN" "RECORD" "[first" "record" "data]" "RECORD" "[second"
[8] "record" "data]" "RECORD" "[third" "record" "data]" "END"
[1] "BEGIN RECORD [first record data] RECORD [second record data] RECORD
[third record data] END"
[1] "BEGIN " " [first record data] "
[3] " [second record data] " " [third record data] END"
output-end
Peter Wolf
Tamas Papp wrote:
>Hi,
>
>I need to parse a data file (output of a measuring device) of the
>following format:
>
>BEGIN RECORD [first record data] RECORD [second
>record data] RECORD
>[third record data]
>END
>
>Line breaks can (and do ;-() occur anywhere. White space behaves very
>much like TeX, eg it is not important whether there are one or more
>spaces or linebreaks as long as there is one of them. It is a text
>file, not binary.
>
>I need to extract the record data I marked with []'s, eg a vector such
>as c("[first record data]", "[second]", ...) would be nice as a
>result.
>
>What functions should I use for this?
>
>Thanks,
>
>Tamas
>
>
>
>
More information about the R-help
mailing list