How to turn my data.frame into a time series?

Asked

Viewed 308 times

1

My data 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 that, I need the first column to have the dates, that is, to stay 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?

1 answer

2

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.