'Trying to create new columns using header information, add a column containing the file name and merge multiple csv files in R

I have only recently started using R and am now trying to automate some tasks with it. I've a task where I want to merge information from ~300 .csv files. Each file is in the same format with information in a header section followed by data in standard columns.

I want to

  1. Create a new column that contains the file name
  2. Create columns that use header information (e.g. lot number) on each row in the file
  3. Merge all csv files in a folder together.

I've seen bits of code that can merge csv files together using list_files(), lapply() and bind_rows() but struggling to get the header information into new columns before merging the csv files together.

sample of csv file

Has anyone a solution to this?

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source