我将一个数据框赋给一个从字符串中获取的变量名。所以当我运行代码时,我不知道变量名是什么。我想将该数据帧传递给另一个函数来绘制它。在不知道其名称的情况下,如何将其传递给函数?
file_name <- file.choose()
fname <- unlist (strsplit (file_name, "\\", fixed = TRUE))
fname <- fname[length(fname)]
waf_no <- unlist (strsplit (fname, "\\s"))
waf_no <- waf_no[grep(waf_no, pattern="WAF")]
data <- read_WAF_file (file_name)
assign(waf_no, flux_calc(data)) #flux calc() calculates and manipulates the data frame
plot_waf(?)我的plot_waf函数非常简单
plot_waf <- function (dataframe) {
library("ggplot2")
qplot(dist,n2o,data=dataframe,shape=treat)
}发布于 2015-06-13 03:57:41
与assign相反的是get
按名称搜索一个对象(get)或零个或多个对象(mget)的
。
因此,您需要像这样运行您的plot函数:
plot_waf(get(waf_no))https://stackoverflow.com/questions/30811156
复制相似问题