Use dynamic name for new column/variable in `dplyr`

Since you are dynamically building a variable name as a character value, it makes more sense to do assignment using standard data.frame indexing which allows for character values for column names. For example: multipetal <- function(df, n) { varname <- paste(“petal”, n , sep=”.”) df[[varname]] <- with(df, Petal.Width * n) df } The mutate function … Read more

How does one access the piped data.frame in dplyr::funs?

If you want to take column sums you can iris %>% select_if(is.numeric) %>% mutate_all(funs(./sum(.))) If you want to take a total sum, you can just store it as another column iris %>% select_if(is.numeric) %>% mutate(totsum = sum(.)) %>% mutate_at(vars(-totsum), funs(./totsum)) I don’t think there is much merit to using dplyr for such non column or … Read more