Dear list members,
I want to recode a data frame but do it for several variables at the same
time. I want to give all the values or equal than 1 a value of 1 and all
the remaining values (0) keep in 0.
data.frame: newdf
var1 var2 var3 var4
A 1 0 4
B 3 2 1
C
Manuel,
Something like this should work for your example.
xx=data.frame(x=c(2, 10), y=c(2, 0))
xx[xx!=0]=1
xx
x y
1 1 1
2 1 0
Bret
On 7/3/2012 8:12 PM, Manuel Spínola wrote:
Dear list members,
I want to recode a data frame but do it for several variables at the same
time. I want to give
Thank you Bret.
What if I need to leave out some variables from my data frame. I have 22
variables and I need to leave the 2 first variables out of the condition.
Best,
Manuel
2012/7/3 Bret Collier b...@tamu.edu
Manuel,
Something like this should work for your example.
Thank you very much Bret.
Best,
Manuel
2012/7/3 Bret Collier b...@tamu.edu
Not very elegant or efficient, but for only a couple of columns needing
left out something simple like this should work.
xx=data.frame(x=c(2, 10), y=c(2, 0), z=c(4, 3))
yy=xx[,2:3]
yy[yy!=0]=1