[R] data file with columns of unequal length

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Fri Oct 23 12:01:53 CEST 2009


Jim Lemon wrote:
> On 10/23/2009 07:58 PM, William Simpson wrote:
>> I am running an expt that presents a point process input x and
>> measures a point process output y. The times of each event are
>> recorded. The lengths of the data records of x and y are necessarily
>> different, and can be different by a factor of 10. I would like to
>> save these data after each experiment as a file with two columns, one
>> for x and one for y.
>>
>> However, R dataframes require columns of equal length. One solution is
>> to fill the "empty" places in y with NAs so it has the same length as
>> x. I view that as unsatisfactory (there are in reality no missing
>> values). Another possibility is to store x and y in separate files. I
>> also view that as unsatisfactory (it is too easy to lose track of the
>> y file corresponding to a given x file).
>>
>> Can anyone suggest a way to deal with this situation?
>>
>>    
> Hi Bill,
> 
> xy<-list(x=1:10,y=1:100)
> 
> Note that this cheerfully ignores how you are going to figure out which
> x goes with which y(s).

As I understand it, they don't come in pairs anyway. For the same reason
a data frame is just the wrong kind of data structure. If you don't want
separate data files, you can use one file with two columns where the
second column is (say) 1 for the x and 2 for the y.

(There are other options, like concatenating the x and the y with some
sort of separator inbetween, but it easily gets painful to read them
back in.)

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list