jeudi 9 février 2017

each {plyr}: Error: Results must have the same dimensions

Vote count: 0

Using each in plyr, the first two commands work without error, but the third one produces the error Error: Results must have the same dimensions. The only difference in the three commands is in the third argument ("mode"=...)

each("mean"=function(x) ifelse(is.numeric(x),mean(x),NA)
   , "median"=function(x) ifelse(is.numeric(x), median(x), NA) 
   , "mode"=function(x) names(which.max(table(x))))

each("mean"=function(x) ifelse(is.numeric(x),mean(x),NA)
   , "median"=function(x) ifelse(is.numeric(x), median(x), NA)
   , "mode"=function(x) ifelse(TRUE, names(which.max(table(x))), NA))

each("mean"=function(x) ifelse(is.numeric(x),mean(x),NA)
   , "median"=function(x) ifelse(is.numeric(x), median(x), NA)
   , "mode"=function(x) ifelse(is.factor(x), names(which.max(table(x))), NA))

I fail to understand why.

asked 37 secs ago

Let's block ads! (Why?)



each {plyr}: Error: Results must have the same dimensions

Aucun commentaire:

Enregistrer un commentaire