在R

时间:2018-04-20 02:13:28

标签: r

我有一个包含多个txts的文件夹,我想将它们作为单独的数据集导入,例如:

datasetpaths <- list.files("C:/OneDrive/R Resources/R Books/Mixed Effects Medels/ZuurDataMixedModelling", full.names = TRUE)
datasetnames <- list.files("C:/OneDrive/R Resources/R Books/Mixed Effects Medels/ZuurDataMixedModelling", full.names = FALSE)
datasetnames <- sub("\\..+", "", datasetnames, perl = TRUE)

datasetnames <- lapply(datasetpaths, FUN = read.table, header = TRUE, dec = ".")

但是这样做之后,我有一个包含多个数据集的列表datasetnames。如何在一次运行中单独导入它们作为单个变量?

1 个答案:

答案 0 :(得分:0)

purrr::map

尝试:

library(tidyverse)

df <- map_df(list.files("yourPath", full.names = TRUE), 
                 read.table, header = TRUE, dec = '.')