Hi everyone, I am trying to read in a tab delimited data file to R that has outliers marked by blank spaces. I would like to be able to tag those as "NA" when the data is read in. I cannot figure out how to do this using the read.table() options. Everything I have tried either puts all the NA on the end of the row when there are missing values instead of on their appropiate columns or won't read the data in at all. Thanks much, Laura -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
detecting blanks in read.table()
3 messages · Laura Forsberg, Thomas Lumley, Peter Dalgaard
On Tue, 31 Jul 2001, Laura Forsberg wrote:
Hi everyone, I am trying to read in a tab delimited data file to R that has outliers marked by blank spaces. I would like to be able to tag those as "NA" when the data is read in. I cannot figure out how to do this using the read.table() options. Everything I have tried either puts all the NA on the end of the row when there are missing values instead of on their appropiate columns or won't read the data in at all.
This seems to work
read.table("foo.dat",sep="\t",na.strings=" ",header=TRUE)
a b c d 1 1 NA 2 3 2 4 5 NA 6 3 NA 7 8 9 where the file is a b c d 1 2 3 4 5 6 7 8 9 ie with tabs replaced by \t a\tb\tc\td 1\t \t2\t3 4\t5\t \t6 \t7\t8\t9 -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Laura Forsberg <toad at alvie-mail.lanl.gov> writes:
Hi everyone, I am trying to read in a tab delimited data file to R that has outliers marked by blank spaces. I would like to be able to tag those as "NA" when the data is read in. I cannot figure out how to do this using the read.table() options. Everything I have tried either puts all the NA on the end of the row when there are missing values instead of on their appropiate columns or won't read the data in at all. Thanks much, Laura
Blank or empty? Using read.delim() or read.table(...,sep="\t") should at least get the columns right. You might need na.strings=" " to prevent it from interpreting the entire column as a factor.
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._