Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/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
rbind正在覆盖R中以前的数据_R - Fatal编程技术网

rbind正在覆盖R中以前的数据

rbind正在覆盖R中以前的数据,r,R,所以,我这里有两个问题,我结合了解决方案,但似乎我没有很好地实施它们。() 因此,我使用read_delim()读取文件,并尝试在将某些数据保存到一种数据类型之前过滤掉它们 data <- data.frame() for (file in files){ name = strsplit(file, split = "\\.")[[1]][1] tmp <- data %>% bind_rows(read_delim(file = file, delim = ";"

所以,我这里有两个问题,我结合了解决方案,但似乎我没有很好地实施它们。()

因此,我使用read_delim()读取文件,并尝试在将某些数据保存到一种数据类型之前过滤掉它们

data <- data.frame()
for (file in files){

  name = strsplit(file, split = "\\.")[[1]][1]

  tmp <- data %>% bind_rows(read_delim(file = file, delim = ";", col_types = cols(
    a = col_double(),
    b = col_double(),
    c = col_character()
    )) %>% mutate(filename = name)
    data_tmp <- tmp %>%
      filter(!str_detect(c, 'a'))
    data <- rbind(data, tmp_data)
}
数据%mutate(文件名=名称)
数据\u tmp%
过滤器(!str_detect(c,'a'))

数据如果我们使用
map
,我们可以使它更紧凑。循环遍历
文件
,使用
读取文件名
读取数据,创建带有文件名子字符串的“文件名”列,过滤行
并将其转换为带有
\u dfr
后缀的单个data.frame

library(purrr)
library(dplyr)
out <- map_dfr(files, ~ {
          file <- .x
         read_delim(file, delim = ";", col_types = cols(
            a = col_double(),
            b = col_double(),
            c = col_character()
            )) %>%
          mutate(filename = str_remove(file, "\\..*")) %>%
          filter(!str_detect(c, 'a'))
        })

非常感谢你。。我仍然需要学习一些东西,我一直在代码中遗漏一些小细节,这导致了所有的错误trouble@akrun是的,很抱歉,我只是想写另一个例子,没有给出我真正的代码
data <- data.frame()
for (file in files){

  name = strsplit(file, split = "\\.")[[1]][1]

  tmp <- read_delim(file = file, delim = ";", col_types = cols(
    a = col_double(),
    b = col_double(),
    c = col_character()
    )) %>% mutate(filename = name)
    tmp_data <- tmp %>%
      filter(!str_detect(c, 'a'))
    data <- rbind(data, tmp_data)
}