I need to convert an xts matrix to a numeric matrix or a data.frame with numeric columns, whatever works. I’ve tried using data.matrix() but the results are still in character format:
class(myxts)
[1] "xts" "zoo"
class(myxts[, "MyNumericColumn"]
[1] "xts" "zoo"
myxts.num = data.matrix(myxts)
class(myxts.num[, "MyNumericColumn"]
[1] "character"
This does the trick although I’m not sure what the performance penalty is:
The call to as.data.frame converts all strings to numeric values, then data.matrix() returns the matrix changing all remaining strings to NAs.