[R] Help with dplyr
David Winsemius
dwinsemius at comcast.net
Fri Nov 6 01:50:11 CET 2015
> On Nov 5, 2015, at 3:59 PM, Axel Urbiz <axel.urbiz at gmail.com> wrote:
>
> Hello,
>
> Is there a way to avoid the warning below in dplyr.
There is an option that lets you turn off warnings. There also a wrapper function called, not surprisingly, … `suppressWarnings`. This is all descibed on:
?warning
—
David.
> I’m performing an operation within groups, and the warning says that the factors created from each group do not have the same levels, and so it coerces the factor to character. I’m using this inside a package I’m developing. I’d appreciate your recommendation on how to handle this.
>
> library(dplyr)
>
> set.seed(4)
> df <- data.frame(pred = rnorm(100), models = gl(2, 50, 100, labels = c("model1", "model2")))
>
> create_bins <- function (pred, nBins) {
> Breaks <- unique(quantile(pred, probs = seq(0, 1, 1/nBins)))
> bin <- data.frame(pred = pred, bin = cut(pred, breaks = Breaks, include.lowest = TRUE))
> bin
> }
>
> res_dplyr <- df %>% group_by(models) %>% do(create_bins(.$pred, 10))
> Warning message:
> In rbind_all(out[[1]]) : Unequal factor levels: coercing to character
>
> Thank you,
> Axel.
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
More information about the R-help
mailing list