[R] Counting number of rain

David Winsemius dwinsemius at comcast.net
Fri Oct 2 06:33:03 CEST 2015


On Oct 1, 2015, at 8:29 PM, Rolf Turner wrote:

> On 02/10/15 15:47, David Winsemius wrote:
> 
> <SNIP>
> 
>> On Oct 1, 2015, at 6:22 PM, Rolf Turner wrote:
>>> 
>>> P.S. I have been unable to find a corresponding vector of the names
>>> of the days of the week, although I have a very vague recollection
>>> of the existence of such a vector.  Does it exist, and if so what
>>> is it called?
>> 
>> It's could called up by strptime because it is mapped to a character
>> vector by the internationalization database:
>> 
>>> format( as.Date(1:7)+2, format="%A")
>> [1] "Sunday"    "Monday"    "Tuesday"   "Wednesday" "Thursday"
>> "Friday" [7] "Saturday"
> 
> <SNIP>
> 
> When I try that (copying and pasting your code so that there's no chance of fumble-fingering) I get:
> 
>> Error in as.Date.numeric(1:7) : 'origin' must be supplied
> 
> Why do these things always happen to *me*???

Or why am I so lucky as to avoid the need for an origin when the help page says the call is:

## S3 method for class 'numeric'
as.Date(x, origin, ...)            # noting no default in the formals


The code says that origin should be supplied if it is missing:

> as.Date.numeric
function (x, origin, ...) 
{
    if (missing(origin)) 
        origin <- "1970-01-01"
    if (identical(origin, "0000-00-00")) 
        origin <- as.Date("0000-01-01", ...) - 1
    as.Date(origin, ...) + x
}


-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list