[R] Selecting groups with R

Fredrik Karlsson dargosch at gmail.com
Sat Aug 22 00:20:58 CEST 2009


Hi John,

I would guess that your Color column is a factor, with three levels
("RED","BLUE","WHITE"), which means that they will all be included in
the output of a table() call, even if they are empty. Try

dataset <- transform(dataset, Color=as.character(Color))

or something similar and then create the table.

/Fredrik

On Fri, Aug 21, 2009 at 11:08 PM, jlwoodard<john.woodard at wayne.edu> wrote:
>
> I have a data set similar to the following:
>
> Color  Score
> RED      10
> RED      13
> RED      12
> WHITE   22
> WHITE   27
> WHITE   25
> BLUE     18
> BLUE     17
> BLUE     16
>
> and I am trying to to select just the values of Color that are equal to RED
> or WHITE, excluding the BLUE.
>
> I've tried the following:
> myComp1<-subset(dataset, Color =="RED" | Color == "WHITE")
> myComp1<-subset(dataset, Color != "BLUE")
> myComp1<-dataset[which(dataset$Color != "BLUE"),]
>
> Each of the above lines successfully excludes the BLUE subjects, but the
> "BLUE" category is still present in my data set; that is, if I try
> table(Color)  I get
>
> RED  WHITE  BLUE
> 82     151      0
>
> If I try to do a t-test (since I've presumably gone from three groups to two
> groups), I get:
> Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my)))
> stop("data are essentially constant") :
>  missing value where TRUE/FALSE needed
> In addition: Warning message:
> In mean.default(y) : argument is not numeric or logical: returning NA
>
> and describe.by(score,Color) gives me descriptives for RED and WHITE, and
> BLUE also shows up as NULL.
>
> How can I eliminate the BLUE category completely so I can do a t-test using
> Color (with just the RED and WHITE subjects)?
>
> Many thanks in advance!!
>
> John
>
>
>
> --
> View this message in context: http://www.nabble.com/Selecting-groups-with-R-tp25088073p25088073.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
"Life is like a trumpet - if you don't put anything into it, you don't
get anything out of it."




More information about the R-help mailing list