I can do this to pick out a few columns from a dataframe.
require(dplyr)
require(magrittr)
df - data.frame (col1 = c(1, 2, 3), col2 = letters[1:3], col3 = LETTERS[4:6])
percent > df percent
select (col1, col2)
I'd like to create a function that works like
F is a function (data, firstCol, secondCol)
{
information percent > percent
substitute (firstCol, secondCol) in the choose box
}
But when I run f(df, col1, col2), I get an error.
Select vars(names(.data),..., env = parent.frame()) has encountered an error:
It is impossible to force a (list) object to type "double."
originating from: (function ()
{
.rs.breakOnError(TRUE)
})()
EDIT -- slightly less trivial example:
Suppose I wanted to do
mtcars %>%
select(cyl, hp) %>%
unique %>%
group_by(cyl) %>%
summarise(avgHP = mean(hp))
but with different datasets and different variable names. I could reuse the code and replace mtcars, cyl, and hp. But I'd rather wrap it all up in a function