I have a column with values: "Adenocarcinoma", "Large-cell carcinoma","Other lung cancer","Small-cell carcinoma","Squamous-cell carcinoma", something like:
> head(covars$newtype[1:5])
[1] Large-cell carcinoma Other lung cancer
[3] <NA> Adenocarcinoma
[5] Adenocarcinoma
I want to change the value to "Ade", Large","Other","Small","Squ" respectively. I have tried several methods and currently plan to fix it by write multiple ifelse. But is there any more efficient way to fix it? Thanks in advance!
We can try using
case_when
from thedplyr
package:You may add additional terms to the above to cover other data not shown.