Re: [R] Selecting groups with R

2009-08-24 Thread Glen Sargeant
jlwoodard wrote: > > > 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 > > How can I eliminate the BLUE category completely so I can do

Re: [R] Selecting groups with R

2009-08-24 Thread Michael A. Miller
To drop empty factor levels from a subset, I use the following: a.subset <- subset(dataset, Color!='BLUE') ifac <- sapply(a.subset,is.factor) a.subset[ifac] <- lapply(a.subset[ifac],factor) Mike > dataset Color Score 1 RED10 2 RED13 3 RED12 4 WHITE22 5 WHITE27 6 WHIT

Re: [R] Selecting groups with R

2009-08-22 Thread Peter Dalgaard
David Winsemius wrote: How can I eliminate the BLUE category completely so I can do a t-test using Color (with just the RED and WHITE subjects)? dataset$Color <- as.character(dataset$Color) or factor(dataset$Color), even. As has been pointed out already, t.test.formula et al. do this in

Re: [R] Selecting groups with R

2009-08-21 Thread jlwoodard
David Winsemius wrote: > > t.test expects two numeric vectors, not a numeric vector and a > grouping indicator. > > > t.test(dataset[dataset$Color=="RED", "Score"], dataset[dataset > $Color=="WHITE", "Score"] ) > > Thank you again, David! I also just realized I could have replaced the

Re: [R] Selecting groups with R

2009-08-21 Thread David Winsemius
On Aug 21, 2009, at 6:36 PM, Don McKenzie wrote: Right, but he just wanted to eliminate "BLUE" as far as I could see. Read his message again. He already showed three methods all of which gave results identical to the one you offered. He asked to be shown why the 0's were appearing in tabl

Re: [R] Selecting groups with R

2009-08-21 Thread David Winsemius
On Aug 21, 2009, at 6:35 PM, jlwoodard wrote: Thank you David! David Winsemius wrote: How did you do the "t-test"? t.test(Score,Color) ?t,test t.test expects two numeric vectors, not a numeric vector and a grouping indicator. > t.test(dataset[dataset$Color=="RED", "Score"],

Re: [R] Selecting groups with R

2009-08-21 Thread Don McKenzie
Right, but he just wanted to eliminate "BLUE" as far as I could see. Your solution does more, of course. On 21-Aug-09, at 3:33 PM, David Winsemius wrote: On Aug 21, 2009, at 6:16 PM, Don McKenzie wrote: dataset[dataset$Color != "BLUE",] Will return a data.frame with Color still a facto

Re: [R] Selecting groups with R

2009-08-21 Thread jlwoodard
Thank you David! David Winsemius wrote: > > > How did you do the "t-test"? > > t.test(Score,Color) John -- View this message in context: http://www.nabble.com/Selecting-groups-with-R-tp25088073p25088342.html Sent from the R help mailing list archive at Nabble.com. _

Re: [R] Selecting groups with R

2009-08-21 Thread David Winsemius
On Aug 21, 2009, at 6:16 PM, Don McKenzie wrote: dataset[dataset$Color != "BLUE",] Will return a data.frame with Color still a factor with three levels. On 21-Aug-09, at 3:08 PM, jlwoodard wrote: I have a data set similar to the following: Color Score RED 10 RED 13 RED

Re: [R] Selecting groups with R

2009-08-21 Thread David Winsemius
On Aug 21, 2009, at 6:08 PM, jlwoodard 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 WH

Re: [R] Selecting groups with R

2009-08-21 Thread Fredrik Karlsson
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 crea

Re: [R] Selecting groups with R

2009-08-21 Thread Don McKenzie
dataset[dataset$Color != "BLUE",] On 21-Aug-09, at 3:08 PM, jlwoodard 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

[R] Selecting groups with R

2009-08-21 Thread jlwoodard
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: m