[R-sig-eco] Replacing values in a data frame
Sarah Goslee
sarah.goslee at gmail.com
Thu Oct 25 21:11:14 CEST 2012
Hi,
2012/10/25 Manuel Spínola <mspinola10 at gmail.com>:
> Dear list members,
>
> I want to replace the values of a numerical variable in a data frame called
> "A".
>
> A
> X1 X2
> 2 1.5
> 3 1
> 4 1.2
>
> How to replace any value greater than 1 by the value 1 in the variable X2.
I think you made a typo? I'm assuming you want to replace values in
column X1 that are greater than 1 with the values in X2? All of your
X1 are greater than 1 in your test example, but:
with(A, ifelse(X1 > 1, X2, X1))
or
A$X1[A$X1 > 1] <- A$X2[A$X1 > 1]
Sarah
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-sig-ecology
mailing list