You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using plyr with .drop = FALSE, I find that factor vectors included in the .variables argument are (at least sometimes) converted to character. The R code below illustrates what I mean:
mydf <- data.frame(aa = factor(rep(1:3, each = 4), levels = 1:4), bb = rep(LETTERS[2:5],
each = 3))
class(mydf$aa) # factor
ans <- ddply(mydf, .(aa), summarize, uLet = length(unique(bb)), .drop = FALSE)
class(ans$aa) # character
ansDrop <- ddply(mydf, .(aa), summarize, uLet = length(unique(bb)), .drop = TRUE)
class(ansDrop$aa) # factor
## End of R code
As is written in the package's NEWS file, as of version 1.5 empty factor levels are indeed preserved when .drop = FALSE. However, the class of the grouping variable(s) seems to vary depending on the value of this argument. It's no big deal to convert the data back to a factor after running ddply, but perhaps an additional modification to the split_labels function to restore factor classes after expand.grid (where stringsAsFactors = FALSE) would provide more consistent output.
All the best
The text was updated successfully, but these errors were encountered:
When using plyr with
.drop = FALSE
, I find that factor vectors included in the .variables argument are (at least sometimes) converted to character. The R code below illustrates what I mean:As is written in the package's NEWS file, as of version 1.5 empty factor levels are indeed preserved when
.drop = FALSE
. However, the class of the grouping variable(s) seems to vary depending on the value of this argument. It's no big deal to convert the data back to a factor after running ddply, but perhaps an additional modification to thesplit_labels
function to restore factor classes afterexpand.grid
(wherestringsAsFactors = FALSE
) would provide more consistent output.All the best
The text was updated successfully, but these errors were encountered: