I added spaces around my fields in CSV file in Vim csv.vim plugin.
Now, I am having difficulties in declaring the column classes as numerical (num
etc).
Having negative values there also cause problems in the following columns
The data can have empty fields.
Data data.csv
Test, test2, test3
, 1 , 1
10.8, -1 , 1
1.1 , 2 , 2
Code
library('methods')
DF <- read.csv("/home/masi/Data/data.csv", header = T, sep = ",", colClasses=c('num','num'))
DF
Output
Error in methods::as(data[[i]], colClasses[i]) :
no method or default for coercing “character” to “num”
Calls: read.csv -> read.table -> <Anonymous>
Execution halted
- Casting to numerical fails when doing
colClasses=c('num','num')
. - Output in Column 3 is considered as
NA
because of one minus mark (-1
) in the second column.
R: 3.3.3
header = T
.