0

I have a folder with 396 csv files.

The first 25 rows of each csv file is the same and so i want to skip them.Next, the 26th row is the header row that i want to keep.

The problem is that the information i am interested in starts in different rows in the csv files.Some start at row 48, others at 36, 32... etc.I want to skip the rows after my header to the start of the row of the needed information. Is there a way to skip the first 25 rows, keep header row (26th), and automate it such that R skips rows after my header until it sees start row with the information.

Additionally, once i reach the row i want,the values is represented every other row or other 2 rows.is there a way to solve this since it is not consistent?

Example:

1. Name
2....
.
.
25...
26.Header
27....
.
.
32/41/etc  12/04/2015   13:49   4     6

I am not sure what code to use but i started thinking of using this code:

files<-list.files("filepath",pattern="*csv", full.names=T)
names(files)<-files
headers = read.csv(files, skip = 1:25, header = F, as.is = T)


edata <- do.call(rbind, lapply(files, read_csv))  

I am not sure how to handle skip issue in the do.call.

Has anyone run into a similar issue and how did you solve it?

Thank you.

3
  • Please review minimal reproducible example. Jul 28, 2017 at 16:31
  • Need more explanation. You can skip the first 25 rows with skip=25. Then, Is there any pattern in the rows you want to keep? Are the rows you want to discard just missing values? Just, copy a real example of your data
    – S Rivero
    Jul 28, 2017 at 16:33
  • i agree. Just use skip = 25 and then delete empty rows....
    – pyll
    Jul 28, 2017 at 16:36

1 Answer 1

0
# First skip the 25 lines
data = read.csv(file, skip = 25, header = T)

# Then remove all other empty rows
data[rowSums(is.na(data)) != ncol(data),]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.