[R] Changing date format

Frederic Ntirenganya ntfredo at gmail.com
Fri Oct 10 08:32:38 CEST 2014


Dear All,

The following function gives me what I wanted.
The input of function is one value and this push me to use sapply function
to call it.

Is there a better way of doing this?

#====================================================
day <- function(x){

         if(x== 60) {
               y = "29 Feb"
         }

         if(x < 60){
                y =  format(strptime(x, format = "%j"), format ="%d-%b")
        }

        if(x > 60){
                y =  format(strptime(x - 1, format = "%j"), format ="%d-%b")
       }
    y
}

sapply(Samaru$Start,day)

 [1] "17-Apr" "27-Apr" "24-Apr" "04-Jun" "25-Apr" "13-May" "22-Apr"
"05-May" "27-Apr" "13-May" "27-Apr"
#=======================================================


On Thu, Oct 9, 2014 at 3:48 PM, Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:

> On 09/10/2014, 8:27 AM, PIKAL Petr wrote:
> > Hi
> >
> >> -----Original Message-----
> >> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> >> project.org] On Behalf Of Frederic Ntirenganya
> >> Sent: Thursday, October 09, 2014 1:32 PM
> >> To: Jim Lemon
> >> Cc: r-help at r-project.org
> >> Subject: Re: [R] Changing date format
> >>
> >> This idea substract 1 for the all column which is not what i want.
> >>
> >> We know that the leap years have 366 days. I don't need to change
> >> anything on them
> >>
> >> the non-leap years have 365 days. This is what i want to change to be
> >> 366 days rather than 365 days.
> >
> > But this is a question of calendar reform not R. I must admit it would
> be a tough job as leap day is needed to stay in tune with solar year. Your
> suggestion would quickly result in out of sync with the Sun.
>
> R Core is powerful, but I doubt if we could reform the calendar in this
> way.
>
> And I'd be against it in any case:  I like to swim on my summer
> vacations, but if August slipped into the winter, the lakes around here
> would be frozen.
>
> Duncan Murdoch
>



-- 
Frederic Ntirenganya
Maseno University,
Kenya.
Mobile:(+254)718492836
Email: fredo at aims.ac.za
https://sites.google.com/a/aims.ac.za/fredo/

	[[alternative HTML version deleted]]



More information about the R-help mailing list