I suppose this need not be strictly time series data, but I couldn't see how else to frame the question...
I have a data table with rows as unique XY locations and columns of ID, X, and Y, and then 12 monthly columns for several climate variables:
- Mean temperature (Tmean) for months 1-12, named Tmean01, Tmean02 ... Tmean12.
- Max temperature (Tmax) for months 1-12, named Tmax01, Tmaxe02 ... Tmax12.
- Min temperature (Tmax) for months 1-12, named Tmax01, Tmaxe02 ... Tmax12.
The data look like this:
ID lat long Tave01 Tave02 Tave03 Tave04 Tave05 Tave06 Tave07 Tave08 Tave09 Tave10 Tave11 Tave12 Tmax01 Tmax02 Tmax03 Tmax04 Tmax05 Tmax06 Tmax07 Tmax08 Tmax09 Tmax10 Tmax11 Tmax12 Tmin01 Tmin02 Tmin03 Tmin04 Tmin05 Tmin06 Tmin07 Tmin08 Tmin09 Tmin10 Tmin11 Tmin12
F102 51.5 -116.3 -12.8 -9.2 -4.6 -0.9 4.1 5.8 9.5 8.1 3.2 -1.1 -7.4 -12.0 -8.0 -2.8 0.4 5.2 10.5 9.9 15.0 14.3 8.1 2.5 -4.8 -7.6 -17.5 -15.6 -9.5 -6.9 -2.2 1.7 3.9 1.9 -1.7 -4.7 -10.0 -16.4
F103 51.5 -116.2 -13.0 -9.5 -4.9 -1.2 4.0 5.7 9.4 8.0 3.1 -1.1 -7.6 -12.3 -7.9 -2.9 0.2 5.0 10.3 9.8 15.0 14.3 8.1 2.7 -4.6 -7.6 -18.1 -16.1 -10.0 -7.3 -2.4 1.7 3.7 1.7 -1.9 -5.0 -10.6 -17.0
F105 51.5 -116.1 -13.7 -10.8 -6.5 -3.5 1.8 4.2 7.6 6.1 1.5 -2.7 -9.1 -13.5 -8.7 -4.7 -1.8 2.2 7.6 7.1 12.2 11.5 5.7 1.1 -6.9 -9.1 -18.8 -17.0 -11.2 -9.2 -3.9 1.2 2.9 0.7 -2.7 -6.5 -11.3 -18.0
F106 51.5 -116.0 -13.7 -10.8 -6.4 -3.3 1.8 4.2 7.7 6.2 1.7 -2.5 -9.0 -13.4 -8.5 -4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 -8.5 -4.2 1.7 5.1 10.2 15.1 14.7 20.3 18.9 13.3 10.4 3.3 -2.8 -16.3 -14.0 -7.7 -4.7 -0.7 3.1 5.2 3.4 -0.4 -3.4 -7.8 -14.2
...
What I would like to have is a time-series layout, where each row represents a monthly entry for each discrete ID with the variables (Tmean, Tmin, Tmax) as columns. So I would end up with 12 rows for each unique ID. Something like this...
ID Month Tave Tmax Tmin
F102 1 -12.8 -8.0 -17.5
F102 2 -9.2 -2.8 -15.6
F102 3 -4.6 0.4 -9.5
F102 4 4.1 5.2 -6.9
...
F102 12 -12.0 -7.6 -16.4
F103 1 -13.0 -7.9 -17.5
F103 2 -9.5 -2.9 -16.1
...
And so forth for each station and each month.
I can brute force this with a loop or something through all variables and populate an expand.grid table or something, but there must be a more elegant (i.e. faster and easier) solution.
I've looked through the reshape package, but can't seem to track down what I need.