Reputation: 6399
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?
Upvotes: 1
Views: 170
Reputation: 61154
Change your code to:
sapply(1:99, function(x) max(listofvectors[[x]]))
or directly use
sapply(listofvectors, max)
Upvotes: 1