Thank you all !! On Tue, Mar 22, 2011 at 3:53 AM, Peter Ehlers [via R] < ml-node+3395720-1679132054-222...@n4.nabble.com> wrote:
> On 2011-03-21 14:39, joe82 wrote: > > > Hello All, > > > > I need help with my dataframe, it is big but here I am using a small > table > > as an example. > > > > My dataframe df looks like: > > X1 X2 X3 > > 1 2011-02 0.00 96.00 > > 2 2011-02 0.00 2.11 > > 3 2011-02 2.00 3.08 > > 4 2011-02 0.06 2.79 > > 5 2011-02 0.00 96.00 > > 6 2011-02 0.00 97.00 > > 7 2011-02 0.08 2.23 > > > > I want values in columns X2 and X3 to be checked if they are greater than > > > 50, if yes, then subtract from '100' > > > > df should look like: > > > > X1 X2 X3 > > 1 2011-02 0.00 4.00 > > 2 2011-02 0.00 2.11 > > 3 2011-02 2.00 3.08 > > 4 2011-02 0.06 2.79 > > 5 2011-02 0.00 4.00 > > 6 2011-02 0.00 3.00 > > 7 2011-02 0.08 2.23 > > > > One more way: > > d <- transform(d, > X1 = pmin(X1, 100 - X1), > X2 = pmin(X2, 100 - X2)) > > [or use within() in place of transform()]. > > Peter Ehlers > > ______________________________________________ > [hidden > email]<http://user/SendEmail.jtp?type=node&node=3395720&i=0&by-user=t>mailing > list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://r.789695.n4.nabble.com/How-to-substract-a-valur-from-dataframe-with-condition-tp3394907p3395720.html > To unsubscribe from How to substract a valur from dataframe with > condition, click > here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3394907&code=bm9udS5idXN5QGdtYWlsLmNvbXwzMzk0OTA3fDIxNDQwMTg0NzY=>. > > -- View this message in context: http://r.789695.n4.nabble.com/How-to-substract-a-valur-from-dataframe-with-condition-tp3394907p3396523.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] ______________________________________________ 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.