计划R
我想在R中创建一个函数,它将从数据框中获取列名,并创建一个新的函数,其参数名称与列名相同,参数与列数一样多。
my_function<-function(data_frame){
return(new_function<-function(#column_name_1,#column_name_2,#column_name3,#column_name_x){
[function does something cool]
}
)
}
例如,如果我有一个数据框:
> dimorphandra
genus_species temp germinability waterpotential
1 Dimorphandra_mollis 30.8 86 0.0
2 Dimorphandra_mollis 32.5 94 0.0
3 Dimorphandra_mollis 35.0 74 0.0
4 Dimorphandra_mollis 37.0 44 0.0
5 Dimorphandra_mollis 39.0 2 0.0
6 Dimorphandra_mollis 41.0 0 0.0
然后我会将my_function应用于它:
my_function(dimorphandra)
哪个会输出:
new_function<-function(genus_species,temp,germinability,water potential){
[function does something cool]
}
如何创建my_function?
非常感谢!