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. jess -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
There _are_ three columns: | is the column _separator_. So give three column names and ignore/discard the third column. Alternatively preprocess the file to remove the incorrect (according to your description) second separator. On Unix piping though sed will do it, and there are lots of other ways. On Wed, 13 Nov 2002, Balint, Jess wrote:> 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.-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._