tornanddesperate
2011-May-04 09:01 UTC
[R] select value from a column depending on a value in another column
Hi everybody I couldn't find the solution to what must be quite a simple problem. Maybe you can help? treatment session period stage wage_accepted market 1 1 1 1 1 25 public 2 1 1 1 1 19 privat 3 1 1 1 1 15 public 4 1 1 1 2 32 public 5 1 1 1 2 13 privat>From this table, I'd like to choose only those values in the column"wage_accepted" that have the value "public" in the column "market". How can I do this? Is there a good general help site for R that would explain basic table manipulations such as this? Thank you very much for your help -- View this message in context: http://r.789695.n4.nabble.com/select-value-from-a-column-depending-on-a-value-in-another-column-tp3494926p3494926.html Sent from the R help mailing list archive at Nabble.com.
Scott Chamberlain
2011-May-04 12:51 UTC
[R] select value from a column depending on a value in another column
This for example could work df <- data.frame(x = seq(1:10), y = rep(c("a","b"),5)) df df$x[df$y %in% "a"] Scott On Wednesday, May 4, 2011 at 4:01 AM, tornanddesperate wrote:> Hi everybody > > I couldn't find the solution to what must be quite a simple problem. Maybe > you can help? > > treatment session period stage wage_accepted market > 1 1 1 1 1 25 public > 2 1 1 1 1 19 privat > 3 1 1 1 1 15 public > 4 1 1 1 2 32 public > 5 1 1 1 2 13 privat > > > From this table, I'd like to choose only those values in the column > "wage_accepted" that have the value "public" in the column "market". How can > I do this? > > Is there a good general help site for R that would explain basic table > manipulations such as this? > > Thank you very much for your help > > > > -- > View this message in context: http://r.789695.n4.nabble.com/select-value-from-a-column-depending-on-a-value-in-another-column-tp3494926p3494926.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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]]
Andrew Robinson
2011-May-04 13:00 UTC
[R] select value from a column depending on a value in another column
Try subset(). Andrew On Wed, May 04, 2011 at 02:01:44AM -0700, tornanddesperate wrote:> Hi everybody > > I couldn't find the solution to what must be quite a simple problem. Maybe > you can help? > > treatment session period stage wage_accepted market > 1 1 1 1 1 25 public > 2 1 1 1 1 19 privat > 3 1 1 1 1 15 public > 4 1 1 1 2 32 public > 5 1 1 1 2 13 privat > > >From this table, I'd like to choose only those values in the column > "wage_accepted" that have the value "public" in the column "market". How can > I do this? > > Is there a good general help site for R that would explain basic table > manipulations such as this? > > Thank you very much for your help > > > > -- > View this message in context: http://r.789695.n4.nabble.com/select-value-from-a-column-depending-on-a-value-in-another-column-tp3494926p3494926.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.-- Andrew Robinson Program Manager, ACERA Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia (prefer email) http://www.ms.unimelb.edu.au/~andrewpr Fax: +61-3-8344-4599 http://www.acera.unimelb.edu.au/ Forest Analytics with R (Springer, 2011) http://www.ms.unimelb.edu.au/FAwR/ Introduction to Scientific Programming and Simulation using R (CRC, 2009): http://www.ms.unimelb.edu.au/spuRs/