dataframe - R, create new column that consists of 1st column or if condition is met, a value from the 2nd/3rd column -
b c d 1 boiler maker <na> <na> 2 clerk assistant <na> <na> 3 senior machine setter <na> 4 operated <na> <na> <na> 5 consultant legal <na> <na>
how create new column takes value in column 'a' unless of other columns contain either legal
or assistant
in case takes value?
here base-r solution. use apply
, any
test every column @ once.
df$col <- as.character(df$a) df$col[apply(df == "legal",1,any)] <- "legal" df$col[apply(df == "assistant",1,any)] <- "assistant"
Comments
Post a Comment