需要使用Purrr :: map_dfc传递数据文件

问题描述 投票:0回答:1

我的代码可以很好地处理90%的H5文件。但是,在200个以上的文件中,我有3个文件具有一列数​​据和一个额外的条目,而不是3212,而它具有3213。我无法进入并在文件中删除这些文件。我只需要完全忽略该特定文件或删除多余的条目即可。 U尝试了pmap和map2,但没有成功。它循环播放5个文件,然后将它们全部打开到一个数据帧中。我试过使用可能性(),但是什么也没做。我不确定如何使用tryCatch

i<- 0
      for(i in seq_along(files)) {
        name <- paste0("file_", i) 
       assign(name,files[[i]]) 


      } 

 H5_files<-lapply(files, H5Fopen)

file_list <- h5ls(H5_files[[1]])
TM_AU<- purrr::map2(H5_files, "/Diagnostics/TM_AU",  h5read)
  units <- purrr::map_char(TM_AU, "Units", H5Fopen)
  # time is contructed from the dt and t0 variables. So that the shots line up for comparison it must only be called once. 

  possible_length <-possibly(H5Fopen, otherwise= NA)
  TM_AU_df <-purrr::map_dfc(TM_AU, "Data", H5Fopen, possible_length) # I get the argument length here 
# Error: Argument 3 must be length 3312, not 3313 
  dt <-purrr::map_dbl(TM_AU, "dt", H5Fopen)
  t0 <-purrr::map_dbl(TM_AU, "t0", H5Fopen)
r hdf5 purrr
1个回答
0
投票

这是我在Hd5f文件中寻找的答案,所有数据都有一个维度,我会尽力而为,直到找到正确的维度。

possible_dim <-possibly((dim= 3212), otherwise= drop )
  RVM_AU_df <-purrr::map_dfc(RVM_AU, "Data", H5Fopen, possible_dim)


它丢弃了大于3212的任何暗淡。感谢所有输入

© www.soinside.com 2019 - 2024. All rights reserved.