> -----Original Message-----
> When I try to apply mean to a list, I get the answer :
> 
> argument is not numeric or logical: returning NA
> 
Example: 
l4 <- list(1:4)
class(l4) #not numeric or logical ...
mean(l4) #same error

#a list is not a number, a logical (TRUE/FALSE) or a vector or array of either 
of those. So mean() can't handle it unaided and tells you what it needs.

#But if your list is a list of numeric objects, unlist will often work.

unlist(l4) #a numeric vector
mean( unlist(l4) ) #no problem

l.some <- list(matrix(1:4, ncol=2), 3:7)
l.some
unlist(l.some) #a numeric vector
mean( unlist(l.some) ) #works

#But a) magic has limits and b) if you want averages, maybe you should not be 
using a list? A vector would save hassle if it fits ...

S Ellison

*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to