[R] working with pairlists imported from HDF5, converting to data frames?

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Mar 16 21:27:02 CET 2005


Does do.call("data.frame", effective) work?  I think it ought to.
If not, as.data.frame(as.list(effective)) would appear to.  In fact almost 
anything you do to a pairlist will turn it into a list, e.g. effective[].

This is really a bug in the hdf5 package, one that you should raise with 
the authors. The help says that groups map to lists, not pairlists, and 
pairlist -> list is easy at C level via PairToVectorList.


On Wed, 16 Mar 2005, Paul Johnson wrote:

> I've used the HDF5 library to bring some data into R. THe verbose output 
> looks like this:
>
>> hdf5load("hdfGraphWed_Mar_16_13_33_37_2005.hdf",load=T,verbosity=1,tidy=T)
> Processing object: cprSeats ...... which is a Group
> Processing object: Seats 0 ...... its a dataset......Finished dataset
> Processing object: Seats 1 ...... its a dataset......Finished dataset
> Processing object: Seats 2 ...... its a dataset......Finished dataset
> Processing object: Seats 3 ...... its a dataset......Finished dataset
> Processing object: Seats 4 ...... its a dataset......Finished dataset
> ... Done group cprSeats
> Processing object: effective ...... which is a Group
> Processing object: AggComp ...... its a dataset......Finished dataset
> Processing object: AggNonComp ...... its a dataset......Finished dataset
> Processing object: CPR ...... its a dataset......Finished dataset
> Processing object: PR ...... its a dataset......Finished dataset
> Processing object: SMD ...... its a dataset......Finished dataset
> ... Done group effective
>
>
> Each item inside the group "effective" is a vector of numbers.  I want to 
> convert effective into a data frame or matrix for use with matplot.
>
> However, R sees effective not as a collection of vectors, but as a pairlist. 
> I'm not a Lisp programmer, so don't understand the significance of the list 
> help page's comment about dotted lists.
>
>> class(effective)
> [1] "pairlist"
>> attributes(effective)
> $names
> [1] "SMD"        "PR"         "CPR"        "AggNonComp" "AggComp"
>
> I can access the elements in effective as list elements, either with 
> effective$SMD or effective[[1]], as in:
>
>> effective[[1]]
>  [1] 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
>  [9] 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
> [17] 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
> [25] 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 4.761905 4.668534
> [33] 4.743833 4.743833 4.694836 4.672897 4.612546 4.612546 4.612546 4.950495
> [41] 4.766444 4.761905 4.329004 4.990020 4.930966 4.906771 4.378284 4.686036
> [49] 4.935834 4.793864 4.793864 4.541326 4.849661 4.730369 4.960317 4.159734
>
>
> But I can't force it into a data frame
>
>> as.data.frame(effective)
> Error in as.data.frame.default(effective) :
>        can't coerce pairlist into a data.frame
>
>
> But I can manually build the dataframe
>
>> 
> data.frame(effective$SMD,effective$PR,effective$CPR,effective$AggNonComp,effective$AggComp)
>
> But that is a bit frustrating for every individual dataset coming in.
>
> Is there a short cut?

-- 
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




More information about the R-help mailing list