0

At present I am using this but it is not giving write figure after for test set

p <- read.csv("steel.csv")
p$Date= parse_date_time(p$Date, "mdy")

train=ts(p$data,c(2014,1),c(2019,06),12)
test=ts(p$data,c(2019,07),c(2020,06),12)

any solution please. also can be used in shiny

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • Hi Akrun, thank for the reply, you I used your code but it is given blank output – Mohit Pandey Jul 16 '22 at 21:23
  • Date price 01/01/2014 0.749788188 02/01/2014 0.778364507 03/01/2014 0.789250724 04/01/2014 0.827806075 05/01/2014 0.915802995 06/01/2014 1.059591776 07/01/2014 1.070477993 08/01/2014 1.071385178 09/01/2014 1.055055853 10/01/2014 1.062313331 11/01/2014 0.938029021 12/01/2014 0.879062013 p <- read.csv("steel.csv") p$Date= parse_date_time(p$Date, "mdy") h <- subset(p,Date >= as.POSIXct('01-01-2014') & Date <= as.POSIXct('12-01-2014')) View(h) can it help you – Mohit Pandey Jul 16 '22 at 21:31
  • even if I use your code result are blank p <- read.csv("steel.csv") p$Date= parse_date_time(p$Date, "mdy") train_dat <- subset(p, Date > as.Date('2014-01-01') & Date < as.Date('2019-06-12')) – Mohit Pandey Jul 16 '22 at 21:33
  • akrun thanks your last code work, I was stuck in this for day hope it will work in shiny to but thank you so much, you really saved me. please put your solution for the community – Mohit Pandey Jul 16 '22 at 21:40
  • Please take some time to review the advice here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. Your question is not reproducible and doesn't give us enough information to help you. – Jon Spring Jul 16 '22 at 22:08

1 Answers1

1

To subset an object of class "ts", use window.

## Using January 2014 as start date:
set.seed(2022)

x <- cumsum(1 + round(rnorm(78), 2))
x <- ts(x, start = c(2014, 1), frequency = 12)

train <- window(x, start = c(2014, 1), end = c(2019, 6))
test <- window(x, start = c(2019, 07), end = c(2020, 6))
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66