R 3.0.3 rbind多个csv文件 [英] R 3.0.3 rbind multiple csv files

查看:190
本文介绍了R 3.0.3 rbind多个csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R 3.0.3:我有40个csv文件,所有的结构相同,我想把 rbind 放入一个文件,所以我可以计算一列的平均值。 p>

我搜索:




  • 此网站

  • R in a Nutshell

  • R_Intro 来源

  • ?rbind帮助在RStudio





任何建议/指针?

解决方案

从这里开始[导入几个文件并将其编入索引]



列出带有.csv扩展名的文件 - 这假定工作目录中只有.csv文件是您要阅读的文件。

  files<  -  list.files(pattern ='\\.csv')

将文件读入列表 - 是否有标题?

 表<  -  lapply .csv,header = TRUE)

rbind文件

  combined.df<  -  do.call(rbind,tables)

然后,您可以找到平均值 - 查找哪些列是数字

  s< ;  -  sapply(combine.df,is.numeric)

找到数字变量的平均值

  colMeans(combined.df [s])


R 3.0.3: I have 40 csv files all structured the same that I want to rbind into one file so I can calculate the mean of one column.

I searched:

  • this website
  • R in a Nutshell
  • R_Intro sources
  • ?rbind Help in RStudio

I cannot find the answer.

Any suggestions/pointers?

解决方案

Using the answer from here [Importing several files and indexing them ]

list files with .csv extension - this assumes that the only .csv files in your working directory are the ones you want to read

files  <- list.files(pattern = '\\.csv')

read files into a list - are there headers?

tables <- lapply(files, read.csv, header = TRUE)

rbind files

combined.df <- do.call(rbind , tables)

You can then find the mean - find which columns are numeric

s <- sapply(combined.df, is.numeric)

find the mean of numeric variables

colMeans(combined.df[s])

这篇关于R 3.0.3 rbind多个csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆