[R] Aggregating daily rainfall raster data to bimontly data

John Wasige johnwasige at gmail.com
Mon Apr 6 07:46:12 CEST 2015


Many thanks everybody for your kind help.

John​

On Mon, Apr 6, 2015 at 12:11 AM, David Winsemius <dwinsemius at comcast.net>
wrote:

>
> On Apr 5, 2015, at 2:40 PM, John Wasige wrote:
>
> > Thanks Jim!
> >
> > Do you have an idea on how I can go about getting bi-monthly (twice a
> > month) results for the month with 28, 29, 30 and 31 daily observations?
> >
> > Thanks for your help
>
> raindate <- seq.Date(as.Date("1982-01-01"), as.Date("1983-01-01"),by=1)
>
>  paste( format( head(raindate,30), "%Y"),
>         cut(as.numeric(format( head(raindate,30),"%d")), c(0,16,32) ),
>        sep="_")
>
>  [1] "1982_(0,16]"  "1982_(0,16]"  "1982_(0,16]"  "1982_(0,16]"
>  [5] "1982_(0,16]"  "1982_(0,16]"  "1982_(0,16]"  "1982_(0,16]"
>  [9] "1982_(0,16]"  "1982_(0,16]"  "1982_(0,16]"  "1982_(0,16]"
> [13] "1982_(0,16]"  "1982_(0,16]"  "1982_(0,16]"  "1982_(0,16]"
> [17] "1982_(16,32]" "1982_(16,32]" "1982_(16,32]" "1982_(16,32]"
> [21] "1982_(16,32]" "1982_(16,32]" "1982_(16,32]" "1982_(16,32]"
> [25] "1982_(16,32]" "1982_(16,32]" "1982_(16,32]" "1982_(16,32]"
> [29] "1982_(16,32]" "1982_(16,32]"
>
> Another method would be to use `cut` on  as.POSIXlt(raindate)$mday
>
> --
> David.
> >
> > John.
> >
> > On Sun, Apr 5, 2015 at 11:25 PM, Jim Lemon <drjimlemon at gmail.com> wrote:
> >
> >> Hi John,
> >> One way is to create an index variable that will divide your data into
> the
> >> appropriate intervals. There are a number of ways to do this. Say you
> want
> >> the "two month" version of bimonthly and you have a date variable
> >> ("raindate") for each observation like "1982-01-01".
> >>
> >> date_order<-paste(rep(month.abb,30),rep(1982:2011,each=12),sep="")
> >>
> >>
> month_index<-factor(format(as.Date(raindate,"%Y-%m-%d"),"%b%Y"),levels=date_order)
> >>
> >> You can then subset the raster matrices by "month_index" and average
> them
> >> for each group
> >>
> >> Jim
> >>
> >> On Mon, Apr 6, 2015 at 3:08 AM, Jeff Newmiller <
> jdnewmil at dcn.davis.ca.us>
> >> wrote:
> >>
> >>> Please stop posting using HTML (as the Posting Guide warns you), and
> >>> follow John Kane's advice. Your reply below is not helping us
> understand as
> >>> well as you seem to think it should.
> >>>
> >>>
> ---------------------------------------------------------------------------
> >>> Jeff Newmiller                        The     .....       .....  Go
> >>> Live...
> >>> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live
> >>> Go...
> >>>                                      Live:   OO#.. Dead: OO#..  Playing
> >>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> >>> /Software/Embedded Controllers)               .OO#.       .OO#.
> >>> rocks...1k
> >>>
> >>>
> ---------------------------------------------------------------------------
> >>> Sent from my phone. Please excuse my brevity.
> >>>
> >>> On April 5, 2015 9:52:18 AM PDT, John Wasige <johnwasige at gmail.com>
> >>> wrote:
> >>>> Thanks Bert,
> >>>>
> >>>> The structure of the data is a raster stack with nraw=867, Ncol=995
> >>>>
> >>>> Rgds John
> >>>>
> >>>>
> >>>> On Sun, Apr 5, 2015 at 6:39 PM, Bert Gunter <gunter.berton at gene.com>
> >>>> wrote:
> >>>>
> >>>>> See ?tapply
> >>>>>
> >>>>> However, as John said, without knowing the structure of your data, it
> >>>>> is impossible to provide a guaranteed recipe. For example, does the
> >>>>> data structure contain date information? -- it would be difficult
> >>>> (but
> >>>>> not impossible depending on data structure) to aggregate by calendar
> >>>>> (bi-monthly, depending on your meaning of "bi") without knowing the
> >>>>> months. Aggregating by every n days would be easy, but that's
> >>>> probably
> >>>>> not what you want.
> >>>>>
> >>>>> Cheers,
> >>>>> Bert
> >>>>>
> >>>>> Bert Gunter
> >>>>> Genentech Nonclinical Biostatistics
> >>>>> (650) 467-7374
> >>>>>
> >>>>> "Data is not information. Information is not knowledge. And knowledge
> >>>>> is certainly not wisdom."
> >>>>> Clifford Stoll
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On Sun, Apr 5, 2015 at 9:13 AM, John Kane <jrkrideau at inbox.com>
> >>>> wrote:
> >>>>>> Someone might if they had any idea of what the data actually looked
> >>>> like
> >>>>> and what you are trying to do. The 'bimonthly' for example, is
> >>>> ambiguous in
> >>>>> English; do you mean every two months or twice a month?
> >>>>>>
> >>>>>> Have a look at
> >>>> https://github.com/hadley/devtools/wiki/Reproducibility
> >>>>> and
> >>>>>
> >>>>
> >>>
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
> >>>>> with special attention to dput() as a method of supplying sample data
> >>>> to
> >>>>> the help list.
> >>>>>>
> >>>>>> John Kane
> >>>>>> Kingston ON Canada
> >>>>>>
> >>>>>>
> >>>>>>> -----Original Message-----
> >>>>>>> From: johnwasige at gmail.com
> >>>>>>> Sent: Sun, 5 Apr 2015 11:34:30 +0200
> >>>>>>> To: r-help at r-project.org
> >>>>>>> Subject: [R] Aggregating daily rainfall raster data to bimontly
> >>>> data
> >>>>>>>
> >>>>>>> Dear community,
> >>>>>>>
> >>>>>>> I have daily rainfall raster data for 30 years (1982_2011). I
> >>>> would like
> >>>>>>> to
> >>>>>>> aggregate daily to bimonthly raster data. Could somebody kindly
> >>>> help on
> >>>>>>> how
> >>>>>>> to go about it!
> >>>>>>>
> >>>>>>> Thanks for your help
> >>>>>>>
> >>>>>>> --
> >>>>>>> John
> >>>>>>>
> >>>>>>>      [[alternative HTML version deleted]]
> >>>>>>>
> >>>>>>> ______________________________________________
> >>>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>>>>>> 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.
> >>>>>>
> >>>>>> ____________________________________________________________
> >>>>>> FREE ONLINE PHOTOSHARING - Share your photos online with your
> >>>> friends
> >>>>> and family!
> >>>>>> Visit http://www.inbox.com/photosharing to find out more!
> >>>>>>
> >>>>>> ______________________________________________
> >>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>>>>> 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.
> >>>>>
> >>>>
> >>>>      [[alternative HTML version deleted]]
> >>>>
> >>>> ______________________________________________
> >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>>> 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.
> >>>
> >>> ______________________________________________
> >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>> 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.
> >>>
> >>
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list