How to transform my data.frame in a time series?

0

My date frame is this:

IPCA.X04.05.2017 IPCA.Beta.1 IPCA.Beta.2 IPCA.Beta.3 IPCA.Beta.4 IPCA.Lambda.1 IPCA.Lambda.2
2           IPCA      0,0526      0,0442     -0,1269      0,0524        1,3477        0,7203

My goal is to create a large database with this data (which is daily). For this, I need the first column to have the dates, that is, to look like this:

            IPCA      Beta.1      Beta.2      Beta.3      Beta.4     Lambda.1         Lambda.2
2     04/05/2017      0,0526      0,0442     -0,1269      0,0524        1,3477        0,7203

How can I make this change?

    
asked by anonymous 05.05.2017 / 22:36

1 answer

1

You can convert this way, but some time series functions require you to use date in posxit format.

df <- data.frame("IPCA", "0.0526", "0.0442")
names(df) <- c("IPCA.X04.05.2017", "IPCA.Beta.1", "IPCA.Beta.2")

df[,1] <- as.character(df[,1])
data <- names(df)[1]
data <- gsub('IPCA.X', '',data)
data <- gsub('\.', '/', data)

names(df)[1] <- 'IPCA'
df[1,1] <- data

        IPCA IPCA.Beta.1 IPCA.Beta.2
1 04/05/2017      0.0526      0.0442
    
05.05.2017 / 23:54