Group members, 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. Thanks, Jason
read.table
4 messages · Oldradio69@aol.com, Uwe Ligges, Brian Ripley
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
Oldradio69 at aol.com wrote:
Group members, 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.
So a data.frame isn't the appropiate structure for your data. You might want to convert it to another structure and remove the appended NAs, or consider to read the data in using scan() and friends. See the R Data Import/Export Manual for details. Uwe Ligges
On Wed, 2 Apr 2003, Prof Brian Ripley wrote:
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.
Sorry, I omitted fill=TRUE from the scan call.
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