简体   繁体   中英

Read and merge row 6 and below from hundreds of csv files in R

I have hundreds of csv files (all in a folder "Project A") each contains the same columns, but the first five rows are not part of the data frame. I need to merge all the rows in every csv file starting from row 6, and create a master sheet in R. Here are my codes.

library(plyr)
library(readr)
myfiles <- list.files(path = "~/Projects/Project A", pattern = "*.csv", full.names = TRUE)
myfiles
do.call("rbind", lapply(myfiles, read.csv, header = TRUE))

How do I skip the first 5 rows? I know I should use skip = 5 , but not sure where to put it or can it be integrated here.

I don't have a good way to test this, but think this will work:

library(tidyverse)

do.call("rbind", lapply(myfiles, read.csv, header = TRUE)) %>% slice(5:n())

Or, as James pointed out:

do.call("rbind", lapply(myfiles, read.csv, skip = 5, header = TRUE))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM