Is there any easy way to pull out the row indexes for a logical matching statment? #################example code######################################### foo <- data.frame(name=c(rep("A", 25), rep("B", 25), rep("C", 25), rep("A", 25)), stuff=rnorm(100), and=rnorm(100), things=rnorm(100)) #this is what I want but I would like the row indexes foo[foo[,1]==A,] ###################################################################### Also, is there a way to get both A or B into the logical statment thanks so much for all of your help Stephen -- Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
If I understand your question, you can try this: which(foo$name %in% c("A", "B")) On Thu, Feb 18, 2010 at 2:01 PM, stephen sefick <ssefick at gmail.com> wrote:> Is there any easy way to pull out the row indexes for a logical > matching statment? > > #################example code######################################### > foo <- data.frame(name=c(rep("A", 25), rep("B", 25), rep("C", 25), > rep("A", 25)), stuff=rnorm(100), and=rnorm(100), things=rnorm(100)) > > #this is what I want but I would like the row indexes > foo[foo[,1]==A,] > ###################################################################### > > Also, is there a way to get both A or B into the logical statment > > thanks so much for all of your help > > Stephen > > -- > Stephen Sefick > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. ?We are mammals, and have not exhausted the > annoying little problems of being mammals. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-K. Mullis > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Hi Stephen, See below. On Thursday 18 February 2010 11:01:25 am stephen sefick wrote:> Is there any easy way to pull out the row indexes for a logical > matching statment? > > #################examplecode#########################################> foo <- data.frame(name=c(rep("A", 25), rep("B", 25), rep("C", 25), > rep("A", 25)), stuff=rnorm(100), and=rnorm(100), things=rnorm(100)) > > #this is what I want but I would like the row indexes > foo[foo[,1]==A,] >row.names(foo[foo[,1]=="A",]) ######################################################################> > Also, is there a way to get both A or B into the logical statment?"|" Best, Ista> > thanks so much for all of your help > > Stephen
Hi: You might also want to consider the use of subset, as in subset(foo, name == "A") or subset(foo, name %in% c("A", "B")) HTH, Dennis On Thu, Feb 18, 2010 at 8:01 AM, stephen sefick <ssefick@gmail.com> wrote:> Is there any easy way to pull out the row indexes for a logical > matching statment? > > #################example code######################################### > foo <- data.frame(name=c(rep("A", 25), rep("B", 25), rep("C", 25), > rep("A", 25)), stuff=rnorm(100), and=rnorm(100), things=rnorm(100)) > > #this is what I want but I would like the row indexes > foo[foo[,1]==A,] > ###################################################################### > > Also, is there a way to get both A or B into the logical statment > > thanks so much for all of your help > > Stephen > > -- > Stephen Sefick > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > > -K. Mullis > > ______________________________________________ > 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]]