[R] need help in if else condition

Shubhasmita Sahani @hubh@@m|t@@@@h@n| @end|ng |rom gm@||@com
Wed Jul 10 09:54:04 CEST 2019


Hello all,
I am trying to run if else condition to alter my data. I have created a
column F with reference to column d  where I want to replace the value to
0 where ever it finds a string or character value like  -,dnr, post and
keep the rest of the rows should have the original value of column d. It is
converting the text to 0 but the numeric values are not the same it is some
value.. will you please help me to figure out why it is happening and what
should be the proper code

here are the code and the output

d=c(1,2,3,"-","dnr","post",10)
e= c(2,2,3,4,5,6,7)
de<- as.data.frame(cbind(d,e))
de$f<-ifelse (de$d=="-"|de$d=="dnr"|de$d=="post",0,de$d)

head(de)

  d e f
1  1 2 2
2  2 2  4
3  3 3 5
4  - 4 0
5  dnr 5 0
6 post 6 0
why the values are changing in  with if else condition


-- 
Thanks & Regards,
Shubhasmita Sahani

	[[alternative HTML version deleted]]



More information about the R-help mailing list