Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重命名循环中的列,R_R_Loops - Fatal编程技术网

重命名循环中的列,R

重命名循环中的列,R,r,loops,R,Loops,我有一个从循环中创建的CSV外部目录读取的数据帧列表: dataList = list() for (i in 0:length-1) { dataList[[i + 1]] <- read.csv(list.files()[length(list.files()) - i], stringsAsFactors = FALSE) %>% select( 'Username' = USERNAME, 'Current.count' = LOG

我有一个从循环中创建的CSV外部目录读取的数据帧列表:

dataList = list()
for (i in 0:length-1) {
  dataList[[i + 1]] <-
    read.csv(list.files()[length(list.files()) - i], stringsAsFactors = FALSE) %>%
    select(
      'Username' = USERNAME,
      'Current.count' = LOGIN.COUNT,
    ) 
}
但是我得到了以下错误

Error: unexpected '='

我在尝试使用用户
重命名()时得到了类似的结果
这可以通过
设置名称
轻松完成(正如@Gregor在评论中提到的)。我们可以将
for
循环中的
select
语句更改为

for (i in 2:length) {
   select(Username, setNames(Current.logins, paste0("Count from month",toString(i)))
}

您的意思是在for循环中使用
select\uuu
而不是
select
?可能使用
setnames
names您可以使用
select(用户名、setnames(Current.logins、paste0(“从月份开始计数”,到字符串(i))
@Gregor yes``选择()使用@akrun规定的集合名更有意义。谢谢你们,它现在正在工作。@akrun如果你们把它写下来作为答案,我会把它标记为正确。我将我的评论作为解决方案发布
for (i in 2:length) {
   select(Username, setNames(Current.logins, paste0("Count from month",toString(i)))
}