Provided that here there is written that I can pass {{colname}} to mutate, where colname is a variable that contains a column name, I cannot figure out why this code doesn't work:
testdf <- data.frame(a=c("Hello", "Hi", "Howy"))
varname <- "a"
testdf %>% mutate(b=nchar({{varname}}))
It returns the number of characters in the letter a:
a b
1 Hello 1
2 Hi 1
3 Howy 1
How can I count the number of characters in a column and assign the value to another column, when the name of the first column is saved into a variable?
mutate(b=nchar(!!sym(varname)))give the expected result?