Reputation: 3
I need your help on aggregating data by year and month and graphing if that's possible.
My data is in a csv file and somehow the data isn't in a good data frame currently showing 1 frequency and not correctly aggregated.
here's the first few part of the data:
YEAR Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 1964 131.4 121.8 125.7 131.9 138.5 144.1 150.5 161.6 160.3 149.7 142.1 139.1
2 1965 133.4 127.9 129.9 132.3 141.9 152.1 156.2 157.1 159.8 149.5 146.6 130.4
3 1966 125.6 128.1 138.5 140.9 142.5 152.5 154.8 175.3 167.9 154.7 137.4 135.4
4 1967 123.8 121.5 120.4 130.2 138.2 147.8 152.3 148.0 155.2 152.8 142.9 127.4
5 1968 120.2 112.9 113.1 117.4 122.9 133.0 150.3 161.3 156.4 150.4 141.7 140.4
6 1969 128.2 118.2 129.6 137.4 151.1 150.3 156.0 162.1 155.5 148.7 139.1 127.1
7 1970 126.1 123.9 122.4 133.0 144.4 146.8 151.8 157.3 152.1 147.9 146.1 134.5
8 1971 131.3 129.8 127.5 132.1 140.3 148.4 153.6 165.1 168.4 150.2 137.8 122.7
9 1972 132.0 131.6 128.2 132.9 142.0 153.7 166.4 164.7 156.4 146.9 144.8 136.2
As you can see, I have it from 1964 January and I was trying to make a time series graph with this data. and failed
Here's the code that I used:
meansealevel<- ts(test_jeju, frequency=12, start=c(1964,1))
and failed, and I figured out that frequency of the data was 1. anyone know how to properly aggregate this data to make correct time series graph?
Upvotes: 0
Views: 430
Reputation: 54277
Try this
test_jeju <- read.table(header=T, text=" YEAR Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 1964 131.4 121.8 125.7 131.9 138.5 144.1 150.5 161.6 160.3 149.7 142.1 139.1
2 1965 133.4 127.9 129.9 132.3 141.9 152.1 156.2 157.1 159.8 149.5 146.6 130.4
3 1966 125.6 128.1 138.5 140.9 142.5 152.5 154.8 175.3 167.9 154.7 137.4 135.4
4 1967 123.8 121.5 120.4 130.2 138.2 147.8 152.3 148.0 155.2 152.8 142.9 127.4
5 1968 120.2 112.9 113.1 117.4 122.9 133.0 150.3 161.3 156.4 150.4 141.7 140.4
6 1969 128.2 118.2 129.6 137.4 151.1 150.3 156.0 162.1 155.5 148.7 139.1 127.1
7 1970 126.1 123.9 122.4 133.0 144.4 146.8 151.8 157.3 152.1 147.9 146.1 134.5
8 1971 131.3 129.8 127.5 132.1 140.3 148.4 153.6 165.1 168.4 150.2 137.8 122.7
9 1972 132.0 131.6 128.2 132.9 142.0 153.7 166.4 164.7 156.4 146.9 144.8 136.2")
meansealevel<- ts(as.vector(t(test_jeju[,-1])), frequency=12, start=c(1964,1))
plot(meansealevel)
Upvotes: 1