'How do I create a ts object that is univariate and captures the first value?

Using ts() in R with a single column csv data set, the first row/value in the column is ignored. If I use that row as a label/header, the data is read as multivariate, which throws an error.

Code looks like this:

entry_ts<-ts(data, frequency = 12, start = c(2016,7), end=c(2022,1))

plot(entry_ts)

entry_ts %>% stl(s.window = "periodic")%>% autoplot()

Data looks like this, in a csv file that I am viewing in Excel- no header row, just values. 950 1083 1028 967 891 918 980 875 961 986 1019 771 666 908 (with additional values...)

I get this, where the July value is showing as the second value in the vector, and because the code is looping back to select that same "first" value again to fill in the last (because it ignored the first value so it doesn't have the right number of values for the start and end dates I gave).

entry_ts Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2016 1083 1028 967 891 918 980 2017 875 961 986 1019 771 666 908 818 815 828 744 871 2018 773 823 827 827 769 757 871 765 866 717 687 776 2019 738 876 866 990 769 844 1067 756 838 774 755 849 2020 768 831 728 737 780 773 969 961 873 761 715 599 2021 670 747 685 701 730 707 710 770 565 623 592 568 2022 1083

I tried to enter a label in the first row, but then get an error that the data is not univariate.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source