Home > Enterprise >  Deleting excess rows from csv files in R and then combining csv files
Deleting excess rows from csv files in R and then combining csv files

Time:11-15

I have over 200 csv files containing temperature data from iButton data loggers. The csv files that are created in onewireviewer have 14 rows of data that I need to get rid of in all of the csv files (see the image below) so that I can then merge csv files based on the column headings.

Onewireviewer output csv file

Id love to be able to automate it in some way as I have around 70 folders (basically one folder per location) with 2-3 csv files from onewireviewer in each folder.

Ive tried messing around with bits of code Ive found online but I couldnt get anything to work and Im now just incredibly frustrated. Any and all help is greatly appreciated!

If it helps I did try running the tidy verse code found here Remove certain rows and columns in multiple csv files under the same folder in R but I get this error:

Column specification -----------------------------------------------------

Delimiter: "," chr (1): 1-Wire/iButton Part Number: DS1921G-F5

i Use spec() to retrieve the full column specification for this data.

i Specify the column types or set show_col_types = FALSE to quiet this message.

Error: Can't subset columns that don't exist.

x Locations 2, 3, 4, 5, 6, etc. don't exist.

i There are only 1 column.

Run rlang::last_error() to see where the error occurred.

In addition: Warning messages:

1: One or more parsing issues, see problems() for details

2: One or more parsing issues, see problems() for details

CodePudding user response:

try something like

library(data.table)
rbindlist(lapply(list.files(...), fread, skip = 14, ...), ...)

where ... are function's arguments.
check out ?list.files, ?data.table::fread and ?data.table::rbindlist to find out more about them.

  •  Tags:  
  • r csv
  • Related