Austin, Matt
2004-Nov-10 04:12 UTC
[R] List seems to drop empty levels of factors when containin g them
I don't get the same result, do you have a package loaded that would change the default behavior (such as Hmisc)?> list(grp.1)[[1]] [1] 1 2 Levels: 1 2> list(grp.1[mask])[[1]] [1] 1 Levels: 1 2> library(Hmisc)<<snip>>> list(grp.1[mask])[[1]] [1] 1 Levels: 1 --Matt> version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 0.0 year 2004 month 10 day 04 language R -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Andrew Robinson Sent: Tuesday, November 09, 2004 19:44 PM To: R-Help Discussion Cc: Andrew Robinson Subject: [R] List seems to drop empty levels of factors when containing them Greetings R community, I am curious about the following behaviour: if I define a factor, and then store a subset of it in a list, the stored version seems to drop levels that were not included in the subset. E.g. ..> mask <- c(T, F) > grp.1 <- factor(c(1,2)) > list(grp.1)[[1]] [1] 1 2 Levels: 1 2> list(grp.1[mask])[[1]] [1] 1 Levels: 1 It is as though the list were redefining the factor and dropping empty levels. I would like to keep them (I am using the list for a two-dimensional tapply). Is there any way to avoid this? I'm using R 2.0.0 on FreeBSD 5.2.1. Thanks, Andrew -- Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : andrewr at uidaho.edu PO Box 441133 W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion. ______________________________________________ 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
Andrew Robinson
2004-Nov-10 04:19 UTC
[R] List seems to drop empty levels of factors when containin g them
Matt, very astute - thanks. I did indeed have Hmisc loaded. Andrew On Tue, Nov 09, 2004 at 08:12:57PM -0800, Austin, Matt wrote:> I don't get the same result, do you have a package loaded that would change > the default behavior (such as Hmisc)? > > > list(grp.1) > [[1]] > [1] 1 2 > Levels: 1 2 > > > list(grp.1[mask]) > [[1]] > [1] 1 > Levels: 1 2 > > > library(Hmisc) > <<snip>> > > > list(grp.1[mask]) > [[1]] > [1] 1 > Levels: 1 > > --Matt > > > version > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 0.0 > year 2004 > month 10 > day 04 > language R > > > -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Andrew Robinson > Sent: Tuesday, November 09, 2004 19:44 PM > To: R-Help Discussion > Cc: Andrew Robinson > Subject: [R] List seems to drop empty levels of factors when containing > them > > > Greetings R community, > > I am curious about the following behaviour: if I define a factor, and > then store a subset of it in a list, the stored version seems to drop > levels that were not included in the subset. E.g. .. > > > mask <- c(T, F) > > grp.1 <- factor(c(1,2)) > > list(grp.1) > [[1]] > [1] 1 2 > Levels: 1 2 > > > list(grp.1[mask]) > [[1]] > [1] 1 > Levels: 1 > > It is as though the list were redefining the factor and dropping > empty levels. I would like to keep them (I am using the list for a > two-dimensional tapply). Is there any way to avoid this? > > I'm using R 2.0.0 on FreeBSD 5.2.1. > > Thanks, > > Andrew > -- > Andrew Robinson Ph: 208 885 7115 > Department of Forest Resources Fa: 208 885 6226 > University of Idaho E : andrewr at uidaho.edu > PO Box 441133 W : http://www.uidaho.edu/~andrewr > Moscow ID 83843 Or: http://www.biometrics.uidaho.edu > No statement above necessarily represents my employer's opinion. > > ______________________________________________ > 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 > > ______________________________________________ > 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-- Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : andrewr at uidaho.edu PO Box 441133 W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion.