Skip to content

if else elseif for data frames

1 message · arun

#
HI,

Much better solution:
library(car)
?set.seed(1)
?dat2<-data.frame(col1=c(sample(c("high","Neutral","low"),10,replace=TRUE)),col2=rep(NA,10))
?x<-dat2$col1
?dat2$col2<-recode(x,'"high"="H";"Neutral"="N";"low"="L"')
dat2
#????? col1 col2
#1???? high??? H
#2? Neutral??? N
#3? Neutral??? N
#4????? low??? L
#5???? high??? H
#6????? low??? L
#7????? low??? L
#8? Neutral??? N
#9? Neutral??? N
#10??? high??? H

A.K.