Skip to content

Instantly share code, notes, and snippets.

@fredbenenson
Created August 26, 2015 21:15
Show Gist options
  • Save fredbenenson/72bf3e6c85fef5310d4b to your computer and use it in GitHub Desktop.
Save fredbenenson/72bf3e6c85fef5310d4b to your computer and use it in GitHub Desktop.
metaprogramming dplyr
dataframe %>% parse(text = paste(sapply(dimensions, function(dimension) {
paste0("mutate(", paste0(dimension, "_average = mean(", dimension, "))"))
}), collapse = " %>% "))
@fredbenenson
Copy link
Author

Figured it out:

eval(
  parse(text = paste(
    c("dataframe",
      lapply(dimensions, function(dimension) {
        paste0("mutate(", paste0(dimension, "_average = mean(", dimension, "))"))
      })
    ), collapse = " %>% ")
  )
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment