Your xts
is a numeric matrix. You can't have multi-types (numeric and factor) in a matrix. The factor is coerced to a factor (as already commented) to have a single type(numeric here).
As a workaround, you can firstly coerce your xts object to a data.frame.
my.daily <- as.data.frame(my.daily)
my.daily[,1] <- code
But why are you trying to do this? You loose all the power and efficiency of xts
to deal with time series.