I am writing a function that will measure the durations of individual vocalizations in a list of audio files. I need these call durations to be saved as numeric lists organized by file. When I write my function to print the task, it will print the lists as I want them but won't save them to an external variable. However, when I leave the print function out, all of the calls will save to one list without specifying which file they came from. Any ideas? Thanks.
Input:
callduration2 <- function(x) {
for (i in x) {
print(timer(i, threshold = 2, msmooth = c(400,90), dmin = 0.1, plot = FALSE)$s.end - timer(i, threshold = 2, msmooth = c(400,90), dmin = 0.1, plot = FALSE)$s.start)
}
}
Output:
[1] 0.1035461 4.1581914 1.4687190
[1] 0.2317160 0.3616587 0.3316719 0.2598854 0.2117248 0.2162683 0.1635642 1.0295460
[1] 0.1035461 4.1581914 1.4687190
[1] 0.2283603 0.1571119 0.1023054
[1] 0.2795895 0.2531787
[1] 0.7232425 1.0376167 0.5624210 0.1235691 0.3389063
OR
Input:
callduration <- function(x) {
output9 <- list()
for (i in x) {
i.t <- timer(i, threshold = 2, msmooth = c(400,90), dmin = 0.1, plot = FALSE)
output9 <- append(output9, i.t$s.end - i.t$s.start)
}
output9
}
Output:
[[1]]
[1] 0.1035461
[[2]]
[1] 4.158191
[[3]]
[1] 1.468719
[[4]]
[1] 0.231716
[[5]]
[1] 0.3616587
[[6]]
[1] 0.3316719
[[7]]
[1] 0.2598854
[[8]]
[1] 0.2117248
[[9]]
[1] 0.2162683
[[10]]
[1] 0.1635642
[[11]]
[1] 1.029546
[[12]]
[1] 0.1035461
[[13]]
[1] 4.158191
[[14]]
[1] 1.468719
[[15]]
[1] 0.2283603
[[16]]
[1] 0.1571119
[[17]]
[1] 0.1023054
[[18]]
[1] 0.2795895
[[19]]
[1] 0.2531787
[[20]]
[1] 0.7232425
[[21]]
[1] 1.037617
[[22]]
[1] 0.562421
[[23]]
[1] 0.1235691
[[24]]
[1] 0.3389063