【发布时间】:2020-04-30 14:38:47
【问题描述】:
我知道有人问过类似的问题,我尝试了多种选择,但仍然收到错误消息。
df_construction <- function(selected_month, selected_variable){
selected_variable_en <- rlang::enquo(selected_variable) #This was an attempt following the link
#filter_criteria <- interp(!is.na(~y), .values = list(y = as.name(selected_variable))) This doesn't work
df1 <- airquality %>%
dplyr::filter(Month == selected_month,
!is.na(selected_variable_en))%>%
select(Month, Day, !!selected_variable)
return(df1)}
df1 <- df_construction(2, "Solar.R")
我的最终目标是在 Shiny 中构建它,从而让用户选择输入作为函数中的参数。
我知道filter 和select 函数不应该以同样的方式处理。
我已按照以下步骤操作:https://www.brodrigues.co/blog/2016-07-18-data-frame-columns-as-arguments-to-dplyr-functions/,但由于!is.na 过滤器而没有成功。
我只想有一个数据框,其中唯一的列是所选月份的 Month 列、Day 列以及用户选择的 Ozone, Solar.R, Wind, Temp 中的任何列,没有任何 NA。
非常感谢您的帮助!!
【问题讨论】: