在R中的函数中引用数据帧前缀

问题描述

我需要按年龄将数据帧分成较小的数据帧。我想为此编写一个函数,但不知道如何避免编写每个变量名。

以下是我过去的完成方式:

CompletedStudy <- StudyCompletion %>%
subset(complete==1)

CompletedStudy_Under24months <- CompletedStudy %>%
subset(child_age<24)

CompletedStudy_Over24months <- CompletedStudy %>%
subset(child_age>=24)

我想创建类似下面的函数

CompletedStudy <- StudyCompletion %>%
subset(complete==1)

AgeCompletion <- function(x) {

x+"_Under24Months" <- x %>%
subset(child_age<24)

x+"_Over24Months" <- x %>%
subset(child_age>=24)
}

AgeCompletion(CompletedStudy)

这可能吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)