Home > Enterprise >  Skip 1st n rows of csv file and read the next line as columns
Skip 1st n rows of csv file and read the next line as columns

Time:08-01

I'm facing a difficulty in reading csv file. My csv file has garbage data in the first 6 lines of the entries, The next line has column entries which I should consider. I tried with skip and header arguments within read.csv ,But none seem to work ,Kindly help me with this ,Thanks for your help in advance.

Below is the format of csv file.

csvEntries,12/2/2022
xxxxx,
                  
logging,0sec
start,2 min
garbage,xyzz
Type,Data,month,year,date,logs,status
1,car,2,2022,12/2,done,success
...
...



I need to skip the first 6st rows and read the next line as column names.

CodePudding user response:

Here is an example for reference.

read.csv(file="/temp/abc.txt", skip = 6, header = T, as.is = T)

Result:

Type    Data    month   year    date    logs    status
<int>   <chr>   <int>   <int>   <chr>   <chr>   <chr>
1   car 2   2022    12/2    done    success
  • Related