问题描述
我在一个文件夹中记录了两周内 20'000 个 1 分钟的 wav 文件。这些都以后缀命名,以表明它们被记录的时间(例如“_213032”= 9:30pm and 32 seconds)。我想在一天中的某些时间(晚上 7 点到凌晨 5 点之间每 20 分钟一次)记录其中的一小部分。因此,我创建了一个具有适当后缀 (file_name_ends) 的向量,并使用以下命令将我想要的所有文件名保存到一个向量 (wav_files) 中:
vector_of_files = file_name_ends[,1]
wav_files = vector()
for(i in 1:length(vector_of_files)){
wav_files = c(wav_files,dir(path,pattern = vector_of_files[i]))
}
然后我在循环中读入这些 wav 文件:
filenames = vector()
for_AR = vector()
for( i in 1:length(wav_files)){
filenames = c(filenames,(wav_files[i])) #add the file name to empty list
load_file = readWave(wav_files[i]) #select the wave file being iterated upon
for_AR = c(for_AR,load_file)}
此组件适用于我需要在此循环中在此文件上运行的其他功能。但是,我现在只想对 20'000 大文件夹中与这些文件名之一匹配的 470 个 .wav 文件运行 seewave 包中的 AR 功能文件。我尝试了许多类似于以下的变体,但都没有成功:
ARvalues = AR(for_AR,datatype = "object",pattern = wav_files)
#or
ARvalues = AR(path,datatype = "files",pattern = vector_of_files)
我怀疑关键在于我的向量之一正确使用了此函数的“pattern =”组件?
如果这有帮助:
head(file_name_ends)
V1
1 _190002
2 _192002
3 _194002
4 _200002
5 _202002
6 _204002
head(vector_of_files)
[1] "_190002" "_192002" "_194002" "_200002" "_202002" "_204002"
head(wav_files)
[1] "20210209_192002.WAV" "20210209_194002.WAV" "20210209_200002.WAV" "20210209_202002.WAV"
head(for_AR) #practicing on four files for Now
[[1]]
Wave Object
Number of Samples: 2784000
Duration (seconds): 58
Samplingrate (Hertz): 48000
Channels (Mono/Stereo): Mono
PCM (integer format): TRUE
Bit (8/16/24/32/64): 16
[[2]]
Wave Object
Number of Samples: 2784000
Duration (seconds): 58
Samplingrate (Hertz): 48000
Channels (Mono/Stereo): Mono
PCM (integer format): TRUE
Bit (8/16/24/32/64): 16
[[3]]
Wave Object
Number of Samples: 2784000
Duration (seconds): 58
Samplingrate (Hertz): 48000
Channels (Mono/Stereo): Mono
PCM (integer format): TRUE
Bit (8/16/24/32/64): 16
[[4]]
Wave Object
Number of Samples: 2784000
Duration (seconds): 58
Samplingrate (Hertz): 48000
Channels (Mono/Stereo): Mono
PCM (integer format): TRUE
Bit (8/16/24/32/64): 16
解决方法
尝试使用 AR
调用 do.call
函数。
library(seewave)
result <- do.call(AR,for_AR)
result