[R] Pipe delimiter ( | ) in "read.delim"

Gabor Grothendieck ggrothendieck at gmail.com
Wed Apr 12 23:57:52 CEST 2006


For the lines you posted this read them in successfully:

read.table("clipboard", sep = "|")

To extract the RD lines you will need two passes:

L <- readLines("clipboard")
L <- grep("^RD", L, value = TRUE)
read.table(textConnection(L), sep = "|")

or you can use read.table(pipe(...), sep = "|")

where ... is a suitable command depending on your OS, i.e. grep,
awk/gawk or findstr but that won't be portable.


On 4/12/06, Zev Ross <zev at zevross.com> wrote:
> Hi R folks,
>
> Can anyone tell me how to read in a pipe ("|") delimited text file? I've
> tried the following:
>
> read.delim("c:/junk/junk.txt",sep="|", skip=7, check.names=FALSE,quote = "",
>    header=F)
>
> The file looks something like the following:
>
> RD|I|04|013|9997|68103|5|7|017|830|20000221|00:00|12.6||6|||||||||||||
> RD|I|04|013|9997|68103|5|7|017|830|20000227|00:00|4.1||6|||||||||||||
> RD|I|04|013|9997|68103|5|7|017|830|20000304|00:00|8.7||6|||||||||||||
> RD|I|04|013|9997|68103|5|7|017|830|20000310|00:00|9.3||6|||||||||||||
> RC|I|04|013|9997|68103|5|7|017|830|20000316|00:00|17.0||6|||||||||||||
>
> While I'm at it, the S-PLUS import GUI has a FilterExpression that will
> limit what it imports. So if I wanted to limit the data above to those
> records beginning with an "RD" the filter expression would be "Col1=
> =\"RD\" ". Is there something similar to this in R?
>
> Thank you, Zev
>
> --
> Zev Ross
> *ZevRoss Spatial Analysis*
> 303 Fairmount Ave
> Ithaca, NY 14850
> (607) 277-0004 (phone)
> (866) 877-3690 (fax toll-free)
> zev at zevross.com
> www.zevross.com
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list