HDF5 grouping/extracting the same data layer from all files in group in R

StackOverflow https://stackoverflow.com/questions/22430978

  •  15-06-2023
  •  | 
  •  

سؤال

I am a relatively new R user. I am having problems extracting the same file from several HDF5 files. This is what I did using the rhdf5 package:

files <- list.files(pattern = ".he5",full.names=TRUE)

The file I can't extract from all the HDF5 Files has the extension

"/HDFEOS/SWATHS/ColumnAmountNO2/Data Fields/ColumnAmountNO2Trop"

When I run the command below for individual files, it works:

NO2he5<-h5read("MA.he5","/HDFEOS/SWATHS/ColumnAmountNO2/Data Fields/ColumnAmountNO2Trop")

How do I translate this to a function that can extract the layer simultaneously for multiple hdf5 files, please?

هل كانت مفيدة؟

المحلول

See lapply:

library(rhdf5)
files <- list.files(pattern = ".he5", full.names = TRUE)
attribute <- "/HDFEOS/SWATHS/ColumnAmountNO2/Data Fields/ColumnAmountNO2Trop"
out.list <- lapply(files, h5read, attribute)

This will store all the read objects into a single object: a list. It is the preferred approach versus creating as many objects as you have files.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top