Hi- I'm trying to read data into R that was exported from Excel, as tab-delimited text. There are some empty cells in the spreadsheet, which I'd like to treat as missing values. I'd like to specify to read.table to use a *single* tab character as the record separator, but I can't seem to do this. First of all, how can I get a tab character in R? Second, is it possible to force read.table not to skip multiple separators? I could preprocess the text, say in perl, to insert missing value strings where needed; is this my only recourse? Thanks for your help-- both now and for all my previous questions! I'm most appreciative. -John -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 3 Jan 2000, John D. Barnett wrote:> Hi- > > I'm trying to read data into R that was exported from Excel, as > tab-delimited text. There are some empty cells in the spreadsheet, > which I'd like to treat as missing values. > > I'd like to specify to read.table to use a *single* tab character as the > record separator, but I can't seem to do this. First of all, how can I > get a tab character in R? Second, is it possible to force read.table > not to skip multiple separators?You can specify tabs in C format, with \t eg R> cat("a\tb\n") a b read.table will generally skip multiple separators I tried the following file (where the tabs are actually tabs) 1 2 3 4 5 R> read.table("/tmp/tmp",sep="\t") V1 V2 V3 1 1 NA 2 2 3 4 5 You might also be able to import data directly from Excel into R for Windows using the COM server, but I haven't tried this. -thomas Thomas Lumley Assistant Professor, Biostatistics 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
John,> I'm trying to read data into R that was exported from Excel, as > tab-delimited text. There are some empty cells in the spreadsheet, > which I'd like to treat as missing values.> I could preprocess the text, say in perl, to insert missing value > strings where needed; is this my only recourse?Suggest you do it before you export the spreadsheet ... If you still have the original spreadsheet, block out the active area containing your data, and search and replace empty cells with a character you can later specify as being NA. Caveat: make sure that the 'find whole cell' option is checked in the find and replace dialog - you could otherwise overwrite all of your data... Doing it this way means less headache for you, requiring only the line with the read.table statement - and no post-import manipulations should be needed. Hope this helps, Pete -- Pete St. Onge pete at seul.org -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._