Reputation: 79
I have this excel data sheet that I want to import into R as a time series object. However, i am not sure of how to go about it.
How would i import this data into R?
Upvotes: 0
Views: 1581
Reputation: 11981
first you cam use the openxlsx
package to read the data:
library(openxlsx)
mydata <- read.xlsx("path to your xlsx")
Afterwards you can use the tidyverse
package to transform your data to a ts
object:
library(tidyverse)
mydata %>%
mutate(Month = 1:n()) %>%
gather(Year, value, -Month) %>%
arrange(Year, Month) %>%
{ts(.$value, start = c(2013, 1), frequency = 12)}
Upvotes: 1