[R] Assigning a larger number of levels to a factor that has fewer levels
izahn at psych.rochester.edu
Thu Apr 7 17:52:00 CEST 2011
The factor() function allows you to specify the levels. So
small.frame$myfactor <- factor(small.frame$myfactor, levels =
should do it.
On Thu, Apr 7, 2011 at 11:47 AM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
> I have larger and a smaller data frame with 1 factor in each - it's
> the same factor:
> myfactor has 10 levels in large.frame and 5 levels in small.frame. All
> 5 levels in small.frame are present in large.frame.
> How could I make levels(small.frame$myfactor) contain all the same
> levels as levels(large.frame$myfactor)?
> In other words, I want table(small.frame$myfactor) to have the same
> number of entries as table(small.frame$myfactor) but with 5 zeros in
> A B C D E F G J I J
> 1 0 1 0 1 0 1 0 1 0
> Thank you very much for your suggestions!
> Dimitri Liakhovitski
> Ninah Consulting
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
University of Rochester
Department of Clinical and Social Psychology
More information about the R-help