I'm trying to understand data.table's fread function. I am hoping to read in a csv file, starting at the row where '!' first appears. The number after "!" changes from table to table, but the "!" is a constant feature.
Here's a version of the data I'm using. When I copy and paste this into a csv file, it works.
113
$LastIndex,AGE_DFN_MORT
!2,PROD_CODE,0,1,2,3,4,5
*,"CDADOA",100,100,100,100,100,100
Here's my attempt:
fread("<file.location>.csv", skip = "!")
What I would expect to happen is that the very first column name would be !2
, followed by PROD_CODE and so on, however it instead populates all column names with V1, V2, V3 etc.
Have I misunderstood something core about the 'skip' argument to the fread function?
EDIT: Thanks - the issue is the absence of the 'header' argument
CodePudding user response:
I tried this, it works:
myData <-
'113
$LastIndex,AGE_DFN_MORT
!2,PROD_CODE,0,1,2,3,4,5
*,"CDADOA",100,100,100,100,100,100'
myData <- fread(myData, skip = '!2', header = TRUE)
myData
# !2 PROD_CODE 0 1 2 3 4 5
# 1: * CDADOA 100 100 100 100 100 100