Skip to content

read.table

4 messages · Oldradio69@aol.com, Uwe Ligges, Brian Ripley

#
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
#
On Tue, 1 Apr 2003 Oldradio69 at aol.com wrote:

            
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.
#
Oldradio69 at aol.com wrote:
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:

            
Sorry, I omitted fill=TRUE from the scan call.