Entering edit mode
6.6 years ago
Kian
▴
50
How I can replace number in R 1 to11, 2 to 22 and 0 to 10, also -9 as NA?
id rs143 rs148 rs149 rs1490
1 02003s -9 1 2 1
2 02003s -9 0 1 2
3 02003s -9 1 1 2
4 02003s -9 0 1 1
5 02003s -9 0 1 1
I want to replace numbers as this format:
id rs143 rs148 rs149 rs1490
1 02003s NA 11 22 11
2 02003s NA 10 11 22
3 02003s NA 11 11 22
4 02003s NA 10 11 11
5 02003s NA 10 11 11
I tried this
df[df==1]<-11
df[df==2]<-22
df[df==0]<-10
But this error occur:
In [<-.factor`(`*tmp*`, thisvar, value = 22) :
invalid factor level, NA generated
check str of dataframe. I guess some of them are factors instead of integers.
As per cpad0112
Also, this must be connected to your other thread: Separate one column in two column R
Thank you cpda0112 and Dear Kevin for responses, how i can solve this problem!
can you paste output from
str(head(df))
, here?