[R] Performing operations only on selected data

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sat Nov 24 18:25:58 CET 2012


?ifelse
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Marcel Curlin <cemarcel at u.washington.edu> wrote:

>I spent some time on this simple question, also searched the forum,
>eventually hacked my way to an ugly solution for my particular problem
>but I
>would like to improve my coding:
>
>I have data of the form:
>df <- expand.grid(group=c('copper', 'zinc', 'aluminum', 'nickel'),
>condition1=c(1:4))
>
>I would like to add a new data column "condition2", with values equal
>to the
>value of condition1 plus a random number from 0-1 (uniform
>distribution)  if
>the value of condition1 is < 1, or just condition1 if the value of
>condition1 is > 1. More generally, my interest is in manipulating the
>values
>of condition1 if they meet one or more criteria, or keeping the values
>the
>same otherwise. Thanks for any thoughts!
>
> 
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Performing-operations-only-on-selected-data-tp4650646.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.




More information about the R-help mailing list