read.table
On Tue, 1 Apr 2003 Oldradio69 at aol.com wrote:
I am using read.table() to read in ASCII data into a data frame. The file has multiple columns that are not the same length. The function gives me errors, or I get 'NA' characters in the blank fields. I want to read these values in to, e.g., perform a two-sample t-test.
You can't use read.table. It is designed to read a data frame where by
definition the columns are the same length.
What you can do is to use scan and remove the NAs as in
tmp <- lapply(scan("foo.txt", list(0, 0)), function(x) x[!is.na(x)])
which will give you a list of two numeric vectors.
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 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595