. Advertisement .
..3..
. Advertisement .
..4..
I don’t know what I’m doing wrong, but I’ve already lost a couple of days struggling with this. Here is my command line:
data(iris)
library(reshape2)
molten.iris <- melt(iris,id.var="Species")
summary(molten.iris)
str(molten.iris)
#------------------------------------------------------------
# Both return warning:
dcast(data=molten.iris,Species~variable,value.var="value",fun.aggregate=min)
dcast(data=molten.iris,Species~variable,value.var="value",fun.aggregate=max)
# Length looks fine though
dcast(data=molten.iris,Species~variable,value.var="value",fun.aggregate=length)
#------------------------------------------------------------
# No warning messages here:
aggregate(value ~ Species + variable, FUN=min, data=molten.iris)
aggregate(value ~ Species + variable, FUN=max, data=molten.iris)
#------------------------------------------------------------
# Or here:
library(plyr)
ddply(molten.iris,c("Species","variable"),function(df){
data.frame(
"min"=min(df$value),
"max"=max(df$value)
)
})
#------------------------------------------------------------
This returns:
Warning message:
In .fun(.value[0], ...) : no non-missing arguments to min; returning Inf
I don’t have any experience with the “no non-missing arguments to min; returning inf.” In this case, how should I change?
The cause: This warning appears because the min/max operators are used on a numeric of length 0.
The warning is reproduced by:
For
mean
you don’t get the warning :The solution: It’s only a warning that has no bearing on the calculation. So you can using
suppressWarnings
to suppress it: