[R] working with pairlists imported from HDF5, converting to data frames?
Paul Johnson
pauljohn at ku.edu
Wed Mar 16 20:52:36 CET 2005
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?
--
Paul E. Johnson email: pauljohn at ku.edu
Dept. of Political Science http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66044-3177 FAX: (785) 864-5700
More information about the R-help
mailing list