[R] problem with apply(m, 1, min, na.rm=T)
Rolf Turner
r.turner at auckland.ac.nz
Wed Jan 21 00:36:56 CET 2009
On 21/01/2009, at 12:26 PM, Czerminski, Ryszard wrote:
> Passing extra arguments to FUN=mean or median in apply
> seems fine, but when FUN=min warnings are generated?
> See below.
>
> Any ideas why?
>
> Best regards,
> Ryszard
>
> Ryszard Czerminski
> AstraZeneca Pharmaceuticals LP
>
>> m
> [,1] [,2]
> [1,] 1 2
> [2,] 3 NA
> [3,] NA NA
>> apply(m, 1, median, na.rm=T)
> [1] 1.5 3.0 NA
>> apply(m, 1, mean, na.rm=T)
> [1] 1.5 3.0 NaN
>> apply(m, 1, min, na.rm=T)
> [1] 1 3 Inf
> Warning message:
> In FUN(newX[, i], ...) : no non-missing arguments to min; returning
> Inf
RTFM:
The minimum and maximum of a numeric empty set are '+Inf' and
'-Inf' (in this order!) which ensures _transitivity_, e.g.,
'min(x1, min(x2)) == min(x1, x2)'. For numeric 'x' 'max(x) ==
-Inf' and 'min(x) == +Inf' whenever 'length(x) == 0' (after
removing missing values if requested).
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
More information about the R-help
mailing list