what am i doing wrong here?
library(quantmod)
getSymbols('^GSPC')
b <- tail(GSPC, 20) #for brevity
is.factor(factor(Cl(b), labels=c('A')))
> TRUE
b$f <- factor(Cl(b), labels=c('A'))
is.factor(b$f)
[1] FALSE
I would like a column in my xts/quantmod object to be a factor. I have no idea why it is not working.
Thanks
It doesn't work because xts/zoo objects are a matrix with an index attribute and you can't mix types in a matrix. GSPC contains numeric data, so you can only add numeric columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With