Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # function to compute summary stat
- compute_box_value <- function(data, vars, funs) {
- f = funs_(funs)
- result <- data %>%
- summarize_at(.cols = vars, .funs = f)
- }
- # simple user defined function that gets count of rows with certain values of x
- equals <- function(x, test_value) {
- sum(x %in% test_value)
- }
- x <- data.frame(value = sample(1:5, 10, TRUE))
- vars <- c("value")
- # this works
- print(compute_box_value(x, vars, "mean(., na.rm = TRUE)"))
- # this works
- summarize_at(x, vars, .funs = "equals", test_value = 1)
- # this doesn't work (error: couldn't find function equals)
- print(compute_box_value(x, vars, "equals(., test_value = 1)"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement