r - Dplyr, filter and SE -
i have data frame 3 columns a, b, c , i'd build function keep rows column lower column (could column b or c)
i know need use filter_ , se make possible dplyr , had @ vignette don't understand how works.'
how transform function se function?
df = data.frame(columna = 1:100, columnb = rnorm(100, 50, 10), columnc = rnorm(100, 50, 10)) fct = function(df,column_name){ df2 = df %>% filter(columna < column) return(df2) }
transforming expression inside filter_
string 1 way it:
fct = function(df, column_name){ df2 = df %>% filter_(paste("columna <", column_name)) return(df2) } nrow(fct(df, "columnb")) ## [1] 50
Comments
Post a Comment