Sample data:
sampdat <- data.frame(grp=rep(c("a","b","c"),c(2,3,5)), x1=seq(0,.9,0.1),x2=seq(.3,.75,0.05), y1=c(1:10), y2=c(11:20))
I would like to have the following data, but i have 100+ variables for which i'd like to apply a function with two variables:
myfun <- function(x,y) {
z=x*y
}
needdat <- sampdat %>% mutate(z1=x1*y1, z2=x2*y2)
What is the most efficient approach to doing this using dplyr's across and summarise?
Thanks in advance for your suggestions/solutions!
Best, SaM