繁体   English   中英

如何使用变量在 gather function 中设置“关键”参数?

[英]How can i set a "key" argument in a gather function using a variable?

如何使用变量在 gather function 中设置“关键”参数? as.character() 和 get() 也不起作用

library(tidyr)
library(dplyr)
path = "C:/Users/lukas/Documents/Projekt/Data/"
files <- list.files(path = path, pattern = "*.csv")

dane <- list()
for (file in files){
  temp_name <- file
 file <- tibble(read.csv(paste(path,file,sep = ""))) %>%
   gather("year", key = temp_name , -country)
 dane <- append(dane,list(file))
}

Error in `ensym2()`:
! Must supply a symbol or a string as argument

我们可以逃脱!!

dane <- list()
for (file in files){
  temp_name <- file
 file <- tibble(read.csv(paste(path,file,sep = ""))) %>%
   gather("year", key = !!temp_name , -country)
 dane <- append(dane,list(file))
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM