Re: [R] convert data frame values

From: Peter Alspach <PAlspach_at_hortresearch.co.nz>
Date: Fri, 04 Apr 2008 11:33:45 +1300

Adrian

If test[,2] is numeric then

test[,2] <- -test[,2]

should be all you need. If it isn't numeric you'll need to convert it first; e.g.,

test[,2] <- -as.numeric(as.character(test[,2]))

which can, of course, be converted back to the original class.

HTH ....... Peter Alspach

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Adrian Johnson
> Sent: Friday, 4 April 2008 10:58 a.m.
> To: r-help
> Subject: [R] convert data frame values
>
> Hello:
> How can I interchange symbols for numeric values in a data frame.
>
> > test
> f s t
> 1 a 1 -1
> 2 b 1 -3
> 3 c -1 1
>
> say I have test d.f . I want to make flip number that are
> positive to negative and negative to positive only for
> numerics in column 's'
>
> my desired result:
>
> > new.test
> f s t
> 1 a -1 -1
> 2 b -1 -3
> 3 c 1 1
>
>
> thanks
> Adrian
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

The contents of this e-mail are privileged and/or confidential to the named  recipient and are not to be used by any other person and/or organisation.  If you have received this e-mail in error, please notify the sender and delete  all material pertaining to this e-mail.



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. Received on Thu 03 Apr 2008 - 22:37:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Apr 2008 - 00:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive