[R] Importing with read.table

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Nov 13 19:57:17 CET 2002


"Balint, Jess" <JBalint at alldata.net> writes:

> Hi all. I have something similar to the following:
> 
> myinfo <- read.table( file = "myfile.txt", sep = "|", col.name = c( "data1",
> "data2" ) )
> 
> myfile.txt:
> a|1|
> b|2|
> 
> However, since there are two pipe (|) characters, it reads it in and thinks
> there should be three columns. This is not the case and I get a warning
> about col.names is wrong length. Is there a way around this? Thanks.

You might use scan and its `flush' argument, or simply

 myinfo <- read.table( file = "myfile.txt", sep = "|")[-3]
 names(myinfo) <- c("data1", "data2")

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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