[R] Changing the order of months within a year
David Winsemius
dwinsemius at comcast.net
Tue Feb 12 19:44:59 CET 2013
On Feb 11, 2013, at 10:09 PM, nick pardikes wrote:
> I have data that looks like below and I would like to re-order the values within the "date" column. I would like to have each year organized like so:
>
> Sep-71
> Oct-71
> Nov-71
> Dec-71
> Jan-71
> Feb-71
> Mar-71
> Apr-71
> May-71
> Jun-71
> Jul-71
> Aug-71
> Sep-72
> Oct-72
> etc...
>
dat1[ order(dat1$year, match(substr(dat1$date, 1,3), month.abb[c(9:12,1:8)] ) ) , ]
--
David.
> Is there any way I can order the column in my own fashion and just move Sep-Dec to the beginning of each year? I am planning on doing some time series analysis with this data and think that the order of months is very important for the time series. I appreciate any suggestions and thank you in advance.
>
>
>
> site date year precipitation temp_max temp_min
> 1 castlepeak Jan-71 1971 26.2903226 38.29032 18.06452
> 2 castlepeak Feb-71 1971 9.1071429 39.60714 17.50000
> 3 castlepeak Mar-71 1971 36.3548387 38.87097 17.77419
> 4 castlepeak Apr-71 1971 14.8333333 44.06667 22.56667
> 5 castlepeak May-71 1971 11.0967742 47.87097 29.22581
> 6 castlepeak Jun-71 1971 7.9000000 62.20000 34.16667
> 7 castlepeak Jul-71 1971 0.4516129 75.45161 44.93548
> 8 castlepeak Aug-71 1971 1.1612903 76.54839 45.96774
> 9 castlepeak Sep-71 1971 0.9333333 68.30000 36.86667
> 10 castlepeak Oct-71 1971 10.1612903 56.22581 31.74194
> 11 castlepeak Nov-71 1971 58.1000000 43.13333 28.43333
> 12 castlepeak Dec-71 1971 56.0645161 30.87097 16.29032
> 13 castlepeak Jan-72 1972 16.7741935 33.90323 15.41935
> 14 castlepeak Feb-72 1972 30.4137931 37.62069 19.82759
> 15 castlepeak Mar-72 1972 12.5161290 46.45161 24.06452
> 16 castlepeak Apr-72 1972 20.9333333 41.23333 22.10000
> 17 castlepeak May-72 1972 3.3870968 53.06452 28.77419
> 18 castlepeak Jun-72 1972 3.7666667 65.60000 37.93333
> 19 castlepeak Jul-72 1972 0.0000000 74.25806 43.45161
> 20 castlepeak Aug-72 1972 0.2258065 73.35484 43.03226
> 21 castlepeak Sep-72 1972 5.4000000 65.66667 37.90000
> 22 castlepeak Oct-72 1972 5.1612903 51.00000 27.38710
> 23 castlepeak Nov-72 1972 23.0666667 40.10000 23.43333
> 24 castlepeak Dec-72 1972 50.7096774 27.00000 10.16129
>
> Nick Pardikes
> PhD Student
> Program in Ecology, Evolution and Conservation Biology
> University of Nevada, Reno
> 303-550-1072
> http://wolfweb.unr.edu/homepage/npardikes/MySite/Welcome.html
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list