I have a dataframe datwe
with 37 columns. I am interested in converting the integer values(1,2,99) in columns 23 to 35 to character values('Yes','No','NA').
datwe$COL23 <- sqldf("SELECT CASE COL23 WHEN 1 THEN 'Yes'
WHEN 2 THEN 'No'
WHEN 99 THEN 'NA'
ELSE 'Name ittt'
END as newCol
FROM datwe")$newCol
I have been using the above sqldf
statements to convert each column separately. I was wondering if there is any other smart way to do this, perhaps apply functions ?
If you require any reproducible data for building dataframe datwe
, I will add it here. Thanks.
Edit:
Example datwe
set.seed(12)
data.frame(replicate(37,sample(c(1,2,99),10,rep=TRUE)))