I am not sure if this is a silly question, but I need a hint now. Apologies in advance.
So I have a random dataframe df and I want to use the mutate_at() function.
x1<-rpois(20,5)
x2<-rpois(20,5)
x3<-rpois(20,2)
df1<-data.frame(x1,x2,x3)
This work perfectly fine if I divide the whole dataframe by one column like this:
library(dplyr)
df1%>%mutate_at(vars(x1:x3),list(All_by_x3=~./x3))
But what I actually want, is that x3 is divided by each column of the dataframe. So I want x3 as the numerator and loop through the different columns in the denominator. What I logically tried is this:
df1%>%mutate_at(vars(x1:x3),list(All_by_x3= x3/ ~.))
but it doesn't work. It feels like there is a simple answer, but I can't see it.
Thanks for any help.