Reputation: 97
I have data that looks like this, below is a screenshot from notepad.
However, when I run the following code to read it into R, I get this.
pdata = read_csv('kd30.csv')
I think it has something to do with the " in the 12" soil moisture, because when I manually change the name to just soil12, it reads in. But I need it to work for the given column names because I have lots of data like this that needs to be read in.
Here is a sample of the data in plain text format data
,12" Soil Moisture (%VWC),16" Soil Moisture (%VWC),20" Soil Moisture (%VWC),Pressure Switch (on|off)
04/25/19 00:15:00,,,,0
04/25/19 00:15:06,36.4465,35.6766,36.3512,
04/25/19 00:30:00,,,,0
04/25/19 00:30:06,36.4522,35.6886,36.3581,
04/25/19 00:45:00,,,,0
04/25/19 00:45:06,36.435,35.6886,36.3581,
04/25/19 01:00:00,,,,0
04/25/19 01:00:06,36.4522,35.6826,36.3581,
04/25/19 01:15:00,,,,0
04/25/19 01:15:06,36.4177,35.6706,36.3649,
04/25/19 01:30:00,,,,0
04/25/19 01:30:05,36.4005,35.6826,36.3649,
04/25/19 01:45:00,,,,0
04/25/19 01:45:06,36.3948,35.6886,36.3717,
04/25/19 02:00:00,,,,0
04/25/19 02:00:06,36.3775,35.6947,36.3717,
Upvotes: 0
Views: 985
Reputation: 3342
According to RFC4108, this is an invalid csv file.
If fields are not enclosed with double quotes, then double quotes may not appear inside the fields.
I suggest you either fix the file or skip the first line of the file when reading it.
Upvotes: 0
Reputation: 2344
You could skip the first line and provide the column names with the col_names
argument to read_csv
:
read_csv('kd30.csv', col_names = c("soil_moisture_12_inch", "soil_moisture_16_inch", "soil_moisture_20_inch", "pressure_switch"), skip = 1)
Upvotes: 1