[R] concatenating factor from list
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Mar 16 00:23:45 CET 2006
Is this ok or is it what you are trying to avoid:
factor(unlist(lapply(cutYield, as.character)))
On 3/15/06, Sebastian Luque <spluque at gmail.com> wrote:
> Hi,
>
> I've run into a ridiculous problem I can't find any solutions for in the
> archives or help pages:
>
> data(barley)
> cutYield <- with(barley, by(yield, variety, cut, breaks = c(0, 30, 60, 90)))
>
> As in this example, I'm using 'by' to return a factor for each level of
> another factor. The problem is that 'by' returns a list of the factors,
> and I need all these factors concatenated. No problem, I said:
>
> unlist(cutYield)
>
> which returns an 'integer' class object, so it's no longer a factor. The
> same happens with:
>
> do.call(c, cutYield)
>
> I could recreate the factor from the integer level codes returned above,
> but this is not good because this means redoing the job already done by
> the function called in 'by', making the code more prone to errors.
>
> Thanks in advance for any pointers,
>
> --
> Sebastian
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list