r - how to assign a missing value in dataframe by another value of dataframe? -
my dataframe
col1 col2 col3 col4 abc 25 35 cde asd 25 45 def 15 36 erf 23 69 erf asd 25 36 erf dfg 85 78
convert
col1 col2 col3 col4 col5 abc 25 35 abc abc asd 25 45 asd def 15 36 def erf 23 69 erf erf asd 25 36 asd erf dfg 85 78 dfg
i need col5 value amnot getting it. have tried using ifelse code
data$col5 <- ifelse(data$col2 =="",levels(data$col1),levels(data$col2))
but getting wrong value.
as per @rolands comment
data$col5 <- ifelse(data$col2 =="",as.character(data$col1),,as.character(data$col2))
Comments
Post a Comment