Home > Net >  Loop through multiple lists to get one value per list in R
Loop through multiple lists to get one value per list in R

Time:04-16

I'm using the seewave packages to get features from audio recordings. The features came back per recording as a list of 14 features per audiofile. These are all put together like this

summary(wav10)

                                  Length Class  Mode
1/10-11.1/20211110_140000.WAV      14     -none- list
1/10-11.1/20211110_140100.WAV      14     -none- list
1/10-11.1/20211110_140200.WAV      14     -none- list
1/10-11.1/20211110_140300.WAV      14     -none- list
1/10-11.1/20211110_140400.WAV      14     -none- list
1/10-11.1/20211110_140500.WAV      14     -none- list
1/10-11.1/20211110_140600.WAV      14     -none- list
1/10-11.1/20211110_140700.WAV      14     -none- list
1/10-11.1/20211110_140800.WAV      14     -none- list
1/10-11.1/20211110_140900.WAV      14     -none- list
1/10-11.1/20211110_141000.WAV      14     -none- list

per audio recording the 'list' consists of:

`wav10[["1/10-11.1/20211110_140000.WAV"]]
$mean
[1] 4765.908

$sd
[1] 6781.333

$median
[1] 361.5

$sem
[1] 13.84234

$mode
[1] 221.8

$Q25
[1] 183.3

$Q75
[1] 8634.7

$IQR
[1] 8451.4

$cent
[1] 4765.908

$skewness
[1] 17.70747

$kurtosis
[1] 424.2355

$sfm
[1] 0.4008524

$sh
[1] 0.8520218

$prec
[1] 0.1

I am only interested in the $mean of every recording. In tried to loop through every file like this:

for(i in seq_along(wav10)) {
   object<- c(print(wav10$'mean')) 
 }

, but I'm not getting the desired output, because every value is NULL. I was hoping someone can help me.

Kind regards,

Tommie

CodePudding user response:

Maybe this works as you expect

   object<- lapply(wav10, `[`, "mean") 
   object
  •  Tags:  
  • r
  • Related