Data.frame for ts daily data in R

2

I can not turn the daily exchange rate to ts.

dados <- read.table("C:/Econometria/Cambio/cambio.txt", header=T, dec=",")
ts(dados), start=c(1994,01,01), freq=1) # Quando faço isso ele muda os dados, acaba aparecendo valores que não estão no arquivo

I also used xts(dados, as.Date(dados, format='%m/%d/%Y')

Could anyone help me?

str(dados)
'data.frame':   5103 obs. of  1 variable:
 $ X1: Factor w/ 4142 levels "-","0,829","0,831",..: 86 81 70 65 74 77 74 74 77 83 ...

dput(dados)
... , "3,9245", "3,9552"), class = "factor")), .Names = "X1", class = "data.frame", row.names = c(NA, 
-5103L))
    
asked by anonymous 18.12.2014 / 13:03

1 answer

2

Diogo, the problem is that their values are not as numbers, but as factor (factors).

This is occurring at the time of reading the database because R is interpreting its data as text (not as number) and transforming it into factor .

If you look at the information you gave with str , the first level is a "-" dash. That's probably what's causing the problem. I suggest you replace these values with zero before reading again.

PS: Out of curiosity, if you want to understand why factors transformed into numbers have seen "other" numbers, I suggest reading this question: Error converting numbers. How to convert factors to numbers? .

    
18.12.2014 / 14:22