jeudi 23 avril 2015

Pass argument to dplyr

I'd like to pass argument to a function which use dplyr.

The idea is to transform the data of a specific column (my argument) of a data frame.

Here is an illustrative example:

example = function(x){
  df %>%
    mutate( paste(x, '_with_noise', sep = '') = x + rnorm(n(), 0, 0.01))
}

The problem is I obtain this error message:

> Error: unexpected '=' in: "  df %>%
>     mutate( paste(x, '_with_noise', sep = '') ="
> > } Error: unexpected '}' in "}"

I also tried to use these but I have the exact same error.

  • mutate_ instead of mutate
  • quote()

Aucun commentaire:

Enregistrer un commentaire