Let's say I have a data frame df
df = data.frame(col1 = c(1:5),col2 = c(2:6))
I want to transform col1 by adding 10 to each value.
I have found several ways to do it for example using the recode
function
df %>% mutate(col1 = recode(col1, "1" = "11", "2"="12", "3"="13", "4"="14", "5"="15"))
or using mutate(across())
function.
df %>% mutate(across(col1, ~.x +10)
So here are my questions :
What are the meanings of x and the . for ? I guess it means for every row of col1 take x and add 10 ?
What could be an easier way to do this transformation ?
Thank you