How can I create squared columns? I know how to do this for individual columns, but I need a loop/function that takes the square of multiple columns at once (all of them starter with "player"). In reality, my dataframe contains a lot of players, so i need an efficient command. Mutate_at is useful, but i also need to create new column names.
df <- data.frame(season = c(1,2,3), player1 = c(1,2,3), player2= c(3,4,5))
#desired result:
# season player1 player2 squared1 squared2
# 1 1 3 1 9
# 2 2 4 4 16
# 3 3 5 9 25