How to transform imported Excel data (.csv) into time series

4

Imported an Excel database for R and need to transform them into time series so that you can analyze them. However, when I make the transformation to time series, the R changes the original values to totally different ones. Here are the steps I used

to import data:

variavel=read.table("dados.csv", header=T, sep=";", dec=",")

After importing the data, the values appeared correctly in the assigned variable, being values of type 5.547,18 ...

to transform data into time series:

library(tseries)# carregando o pacote séries temporais

ts.variavel=ts(variavel, start=c(2000,1), frequency=12) # fazendo a transformação

After the above transformation, when I will query the data they appear fully changed, for example, the value of 5,547.18 turned 15, the value 5344.47 turned 7, the value 5.053.42 turned 2 and so on. Strange, is not it ?! What am I doing wrong?

    
asked by anonymous 05.07.2015 / 14:55

1 answer

1

I believe the problem is reading the data.

Apparently your data has a thousands separator that R does not understand. Therefore it reads the variables as factor , which is then transformed into an integer.

The easiest way to solve this problem is: in excel itself format the columns so as not to have the thousands separator.

Verify that the data is being read correctly with:

str(variavel)

This function should indicate that your data is of the numeric type and not of the type factor. Example:

'data.frame':   100 obs. of  1 variable:
 $ x: num  0.426 0.664 0.844 0.76 0.781 ...
    
05.07.2015 / 15:58