0

I have successfully loaded in the rhdf5 package, but am unable to open the file and create an R data frame. I have read here here and here but am still unclear. I have also tried the hdfdump but that results in error.

How do I read in the HDF5 file? I know I want all of the columns and do not need to group, but rather would like one full data frame. Thanks

Community
  • 1
  • 1
Jebediah15
  • 754
  • 3
  • 18
  • 39

1 Answers1

1

I downloaded file "h5ex_t_string.h5" at random from here to use as an example.

The way to read a .h5 file is the following:

library(rhdf5)   #load library
h5ls("h5ex_t_string.h5")  #this will show you the name to use below in the argument

> h5ls("h5ex_t_string.h5")
  group name       otype dclass dim
0     /  DS1 H5I_DATASET STRING   4   #so the name is DS1

D = h5read("h5ex_t_string.h5",name='DS1') #use the filename and the name to read file

> D   #Weird message in the file but I randomly downloaded it 
[1] "Parting" "is such" "sweet  " "sorrow."

The h5read function returns an array which you can then convert into a data.frame if you like

> a<-data.frame(D)
> a
        D
1 Parting
2 is such
3 sweet  
4 sorrow.
LyzandeR
  • 37,047
  • 12
  • 77
  • 87