Hi everyone, I know there have been several requests regarding subsetting before, but none of them really helps with my problem: I'm trying to subset only infected individuals from the REC2 data.frame:> str(REC2)'data.frame': 362 obs. of 7 variables: $ RINGNO : Factor w/ 370 levels "BL17546","BL17577",..: 78 81 67 41 58 66 17 $ year : Factor w/ 8 levels "Y2002","Y2003",..: 1 2 1 2 1 1 2 1 1 3 ... $ ccFLEDGE : int 6 6 6 5 6 7 6 7 6 5 ... $ rec2012 : int 2 1 2 2 1 2 1 1 1 0 ... $ binage : Factor w/ 2 levels "ad","juv": 1 2 1 1 1 1 1 1 1 1 ... $ INFECTION: Factor w/ 2 levels "Infected ","Uninfected ": 2 1 2 1 2 2 1 2 2 1 ... $ all.rsLD : num -4.62 -6.19 -3.62 -4.19 -2.62 ... using either RECinf<-REC2[which (REC2$INFECTION=="Infected"),] or RECinf<-subset(REC2, INFECTION=="Infected") in both cases I get empty data frame (0 observations):> str(RECinf)'data.frame': 0 obs. of 7 variables: $ RINGNO : Factor w/ 370 levels "BL17546","BL17577",..: $ year : Factor w/ 8 levels "Y2002","Y2003",..: $ ccFLEDGE : int $ rec2012 : int $ binage : Factor w/ 2 levels "ad","juv": $ INFECTION: Factor w/ 2 levels "Infected ","Uninfected ": $ all.rsLD : num When subsetting, R doesn't return any warning or error message. Besides, I used same codes many times before and they worked perfectly well. Any ideas why this case is different? Thanks for your help, Kasia [[alternative HTML version deleted]]
Hi Kasia, You need subset(REC2, INFECTION=="Infected ") (note the space after "Infected"). HTH, Jorge.- On Fri, May 3, 2013 at 7:48 PM, Katarzyna Kulma <katarzyna.kulma@gmail.com>wrote:> Hi everyone, > > I know there have been several requests regarding subsetting before, but > none of them really helps with my problem: > > I'm trying to subset only infected individuals from the REC2 data.frame: > > > str(REC2) > 'data.frame': 362 obs. of 7 variables: > $ RINGNO : Factor w/ 370 levels "BL17546","BL17577",..: 78 81 67 41 58 > 66 17 > $ year : Factor w/ 8 levels "Y2002","Y2003",..: 1 2 1 2 1 1 2 1 1 3 > ... > $ ccFLEDGE : int 6 6 6 5 6 7 6 7 6 5 ... > $ rec2012 : int 2 1 2 2 1 2 1 1 1 0 ... > $ binage : Factor w/ 2 levels "ad","juv": 1 2 1 1 1 1 1 1 1 1 ... > $ INFECTION: Factor w/ 2 levels "Infected ","Uninfected ": 2 1 2 1 2 2 1 2 > 2 1 ... > $ all.rsLD : num -4.62 -6.19 -3.62 -4.19 -2.62 ... > > using either > > RECinf<-REC2[which (REC2$INFECTION=="Infected"),] > > or > > RECinf<-subset(REC2, INFECTION=="Infected") > > in both cases I get empty data frame (0 observations): > > > str(RECinf) > 'data.frame': 0 obs. of 7 variables: > $ RINGNO : Factor w/ 370 levels "BL17546","BL17577",..: > $ year : Factor w/ 8 levels "Y2002","Y2003",..: > $ ccFLEDGE : int > $ rec2012 : int > $ binage : Factor w/ 2 levels "ad","juv": > $ INFECTION: Factor w/ 2 levels "Infected ","Uninfected ": > $ all.rsLD : num > > When subsetting, R doesn't return any warning or error message. Besides, I > used same codes many times before and they worked perfectly well. Any ideas > why this case is different? > > Thanks for your help, > Kasia > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > 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. >[[alternative HTML version deleted]]
You have an extra space in the INFECTION factors. Use REC2[REC2$INFECTION=="Infected ",] or subset(REC2, INFECTION=="Infected ") No need to use which here. On May 3, 2013, at 5:48 AM, Katarzyna Kulma wrote:> Hi everyone, > > I know there have been several requests regarding subsetting before, but > none of them really helps with my problem: > > I'm trying to subset only infected individuals from the REC2 data.frame: > >> str(REC2) > 'data.frame': 362 obs. of 7 variables: > $ RINGNO : Factor w/ 370 levels "BL17546","BL17577",..: 78 81 67 41 58 > 66 17 > $ year : Factor w/ 8 levels "Y2002","Y2003",..: 1 2 1 2 1 1 2 1 1 3 ... > $ ccFLEDGE : int 6 6 6 5 6 7 6 7 6 5 ... > $ rec2012 : int 2 1 2 2 1 2 1 1 1 0 ... > $ binage : Factor w/ 2 levels "ad","juv": 1 2 1 1 1 1 1 1 1 1 ... > $ INFECTION: Factor w/ 2 levels "Infected ","Uninfected ": 2 1 2 1 2 2 1 2 > 2 1 ... > $ all.rsLD : num -4.62 -6.19 -3.62 -4.19 -2.62 ... > > using either > > RECinf<-REC2[which (REC2$INFECTION=="Infected"),] > > or > > RECinf<-subset(REC2, INFECTION=="Infected") > > in both cases I get empty data frame (0 observations): > >> str(RECinf) > 'data.frame': 0 obs. of 7 variables: > $ RINGNO : Factor w/ 370 levels "BL17546","BL17577",..: > $ year : Factor w/ 8 levels "Y2002","Y2003",..: > $ ccFLEDGE : int > $ rec2012 : int > $ binage : Factor w/ 2 levels "ad","juv": > $ INFECTION: Factor w/ 2 levels "Infected ","Uninfected ": > $ all.rsLD : num > > When subsetting, R doesn't return any warning or error message. Besides, I > used same codes many times before and they worked perfectly well. Any ideas > why this case is different? > > Thanks for your help, > Kasia > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.