I am struggling with creating a new column, which should be constructed as row-wise weighted means of the X and Y variables. The reason I want to use weighted.mean() is the na.rm functionality which I need for my purpose.
I have the dataframe
library(tidyverse)
seed(2021)
df <- tibble(x = rnorm(10,0,5),
y = rnorm(10,0,10))
And I try to create the new column like so:
df <- df %>% mutate(z = weighted.mean(cbind(x,y),cbind(rep(c(0.2,0.8),10))))
However, this yields a row filled with the same constant, so I do not seem to specify that I need rowwise operations. I would appreciate a guiding hand - thanks!
/F