xts convert data frame to character

r, xts

Solution

You're confused about the nature of xts/zoo objects. They are matrices with an ordered index attribute, therefore you cannot mix types in xts/zoo objects like you can in a data.frame.

The reason your object is being converted to character is because some of the values in your file are not numeric. This is also why you get the `NAs introduced by coercion` error when you tried hd1's solution.

So the answer to your question is, "fix your CSV file", but we can't help you fix it unless you show us the file's contents.

Problem

I have a csv file and extract data using ``` banknifty <- as.xts(read.zoo("banknifty.csv",sep=",",tz="" ,header=T)) ``` `read.zoo()` extracts the data frame with numeric values but as I apply `as.xts()`, the `data. frame`'s numeric values get converted to characters. ``` # banknifty[1,] gives 2008-01-01 09.34:00 "10" "12" "13" ``` I want `as.xts` should return `data.frame` with numeric values. How to avoid this problem?

Original source