Вопрос

I have a list of vectors:

[[1]]
[1] 4 2 2  5 6 5 
[[2]]
[1] 30 9 320 2
...
[[99]]

I would like to apply a function over all of the vectors in the list.

sapply(1:99, function(x) listofvectors[[x]], max)

I get the error:

Error in FUN(1:99[[1L]], ...) : unused argument (.Primitive("max"))

I get the same error for mean() or any other function. What am I doing wrong?

Это было полезно?

Решение

Change your code to:

sapply(1:99, function(x) max(listofvectors[[x]]))

or directly use

sapply(listofvectors, max)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top