亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用rbind將多個.csv文件加載到R中的單個數據幀中的函數有什么問題?

使用rbind將多個.csv文件加載到R中的單個數據幀中的函數有什么問題?

智慧大石 2019-11-30 14:12:04
我編寫了以下函數來組合300個.csv文件。我的目錄名稱是“ specdata”。我已經完成了以下執行步驟,x <- function(directory) {         dir <- directory        data_dir <- paste(getwd(),dir,sep = "/")        files  <- list.files(data_dir,pattern = '\\.csv')        tables <- lapply(paste(data_dir,files,sep = "/"), read.csv, header = TRUE)        pollutantmean <- do.call(rbind , tables)         }# Step 2: call the functionx("specdata")# Step 3: inspect resultshead(pollutantmean)Error in head(pollutantmean) : object 'pollutantmean' not found我怎么了 誰能解釋一下?
查看完整描述

3 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

```{r echo = FALSE, warning = FALSE, message = FALSE}


setwd("~/Data/R/BacklogReporting/data/PastDue/global/") ## where file are located


path = "~/Data/R/BacklogReporting/data/PastDue/global/"

out.file <- ""

file.names <- dir(path, pattern = ".csv")

for(i in 1:length(file.names)){

  file <- read.csv(file.names[i], header = TRUE, stringsAsFactors = FALSE)

  out.file <- rbind(out.file, file)

}


write.csv(out.file, file = "~/Data/R/BacklogReporting/data/PastDue/global/global_stacked/past_due_global_stacked.csv", row.names = FALSE) ## directory to write stacked file to


past_due_global_stacked <- read.csv("C:/Users/E550143/Documents/Data/R/BacklogReporting/data/PastDue/global/global_stacked/past_due_global_stacked.csv", stringsAsFactors = FALSE)


files <- list.files(pattern = "\\.csv$") %>%  t() %>% paste(collapse = ", ")

```


查看完整回答
反對 回復 2019-11-30
  • 3 回答
  • 0 關注
  • 712 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號