wtd.quantile and tidyverse

Hi, I´m trying to use the function wtd.quantile from the library "weights" but I have problems if I try to run it with pipes. Here is my example

library(tidyverse)
library(weights)

my_data <- tibble(Var_1 = c(900, 1500, 350, 1200, 750, 100,125,250,300),
                  Var_2 = c(385, 988, 150, 355,555, 900,20, 25, 500),
                  Gender = c("W", "W", "W", "M", "M", "W", "W", "M", "W"),
                  my_weights = c(2.2, 3.1, 8.2, 4.2, 5.3, 6.8, 12, 25, 1)) 

my_data %>%
  filter(Gender  == "W") %>%
  wtd.quantile(Var_1, weights= my_weights) 

# I also tried 

my_data %>%
  filter(Gender  == "W") %>%
  wtd.quantile(my_data$Var_1, weights= my_data$my_weights) 

any help?

my_data %>%
  filter(Gender == "W") %>%
  { wtd.quantile(.$Var_1, weights = .$my_weights) }
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.