Hi, I was trying to extract certain rows from a table. For example, if the value in the first column is "a", "d", "k", or "z", then I would like to extract these rows. In other words, if the value in the column is also an element in my list (a,d,k,z), then I would like to extract the row. I've looked in the archives and the solutions I could find were restriced to the value in the row name being a single element. thanks for the help, Tim __________________________________________________ [[alternative HTML version deleted]]
Hi, I was trying to extract certain rows from a table. For example, if the value in the first column is "a", "d", "k", or "z", then I would like to extract these rows. In other words, if the value in the column is also an element in my list (a,d,k,z), then I would like to extract the row. I've looked in the archives and the solutions I could find were restriced to the value in the row name being a single element. thanks for the help, Tim __________________________________________________ [[alternative HTML version deleted]]
Liaw, Andy
2005-Apr-23 18:53 UTC
[R] extracting selected rows, based on a 'list' of values
[No need to post the same message twice, please.] Try something like: dat <- data.frame(a=sample(c("a", "b", "d", "k", "z"), 30, replace=TRUE), b=runif(30)) subset(dat, a %in% c("a", "d", "k", "z")) Andy> From: Tim Smith > > Hi, > > I was trying to extract certain rows from a table. For > example, if the value in the first column is "a", "d", "k", > or "z", then I would like to extract these rows. In other > words, if the value in the column is also an element in my > list (a,d,k,z), then I would like to extract the row. > > I've looked in the archives and the solutions I could find > were restriced to the value in the row name being a single element. > > thanks for the help, > > Tim