head(df)
genotype.og label genotype
MT1 MT1 MT
MT2 MT2 MT
MT3 MT3 MT
MT4 MT4 MT
MT5 MT5 MT
MT6 MT6 MT
WT1 WT1 WT
WT4 WT4 WT
WT11 WT11 WT
WT13 WT13 WT
WT27 WT27 WT
WT28 WT28 WT
WT74 WT74 WT
WT53 WT53 WT
WT68 WT68 WT
WT84 WT84 WT
WT92 WT92 WT
WT95 WT95 WT
Somewhere down the rows I have rows with WT1..WTn. Trying to change only few elements from the label column without changing others. Made a variable called old that holds the names of elements that need to be replaced/renamed.
Code
old = c("WT1","WT4","WT11","WT13","WT27","WT28","WT74","WT53","WT68","WT84","WT92","WT95")
new = c("WS1","WS4","WS11","WS13","WS27","WS28","WS74","WS53","WS68","WS84","WS92","WS95")
df$label_new <- df$label %>% rename_if(vars(old), ~ new)
Error
Error in UseMethod("tbl_vars") :
no applicable method for 'tbl_vars' applied to an object of class "character"
desired output
genotype.og label genotype label_new
MT1 MT1 MT MT1
MT2 MT2 MT MT2
MT3 MT3 MT MT3
MT4 MT4 MT MT4
MT5 MT5 MT MT5
MT6 MT6 MT MT6
WT1 WT1 WT WS1
WT4 WT4 WT WS4
WT11 WT11 WT WS11
WT13 WT13 WT WS13
WT27 WT27 WT WS27
WT28 WT28 WT WS28
WT74 WT74 WT WS74
WT53 WT53 WT WS53
WT68 WT68 WT WS68
WT84 WT84 WT WS84
WT92 WT92 WT WS92
WT95 WT95 WT WS95
What am I missing?