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

Viewed 32

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.

1 Answers

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))
Related