I’ve narrowed it down to a very small example so I’m sure it’s something very silly.
I have the file test.delete with these contents:
Rock,bird
1350909372121900000,55.20000
1350909372318100000,55.30000
1350909382020900000,55.20000
1350909382029600000,55.20000
1350909384311100000,55.20000
and then I do:
test = read.csv('test.delete', colClasses=c('character','numeric'))
but all columns seem to be read in as character:
> apply(test, 2, class)
Rock bird
"character" "character"
Why is this?
read.csvis working as you want. You’re misusingapplyhere.If you run
stron the imported data, you should see that the other variable is numeric. But when you callapply, the data frame is coerced to a matrix, which only handles one data type, and everything is coerced to character.As safer way to check the column classes would be to use
lapply, since a data.frame is in reality a list.