Re: [R] Counting number of rain

2015-10-02 Thread Duncan Murdoch
On 01/10/2015 11:29 PM, Rolf Turner wrote:
> On 02/10/15 15:47, David Winsemius wrote:
> 
> 
> 
>> 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"
> 
> 
> 
> 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*???

The zoo package replaces as.Date.numeric() with a function that assumes
an origin of "1970-01-01".  There may be other packages that also make a
replacement like this.  David appears to have one of them attached, and
you don't.

Duncan Murdoch

__
R-help@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.


Re: [R] Counting number of rain

2015-10-02 Thread David Winsemius

On Oct 2, 2015, at 2:33 AM, Duncan Murdoch wrote:

> On 01/10/2015 11:29 PM, Rolf Turner wrote:
>> On 02/10/15 15:47, David Winsemius wrote:
>> 
>> 
>> 
>>> 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"
>> 
>> 
>> 
>> 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*???
> 
> The zoo package replaces as.Date.numeric() with a function that assumes
> an origin of "1970-01-01".  There may be other packages that also make a
> replacement like this.  David appears to have one of them attached, and
> you don't.

Quite right, Duncan. I failed to include the  even 
though it was staring me in the face. My wife says I have an extreme case of 
"refrigerator blindness" which now seems to be spreading to other areas of my 
cognitive activities.

Sorry, Rolf.
-- 
David.

> 
> Duncan Murdoch
> 

David Winsemius
Alameda, CA, USA

__
R-help@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.


Re: [R] Counting number of rain

2015-10-02 Thread Rolf Turner

On 03/10/15 04:42, David Winsemius wrote:


On Oct 2, 2015, at 2:33 AM, Duncan Murdoch wrote:





The zoo package replaces as.Date.numeric() with a function that
assumes an origin of "1970-01-01".  There may be other packages
that also make a replacement like this.  David appears to have one
of them attached, and you don't.


Quite right, Duncan. I failed to include the  even though it was staring me in the face. My wife
says I have an extreme case of "refrigerator blindness" which now
seems to be spreading to other areas of my cognitive activities.

Sorry, Rolf.


Quite alright.  The syndrome is *very* familiar to me! :-)

cheers,

Rolf



--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@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.


Re: [R] Counting number of rain

2015-10-01 Thread David L Carlson
You should always reply to the list since other posters may have other 
suggestions. Assuming your data frame is called rain:

> str(rain)
'data.frame':   2192 obs. of  4 variables:
 $ Year  : int  1960 1960 1960 1960 1960 1960 1960 1960 1960 1960 ...
 $ Month : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Day   : int  1 2 3 4 5 6 7 8 9 10 ...
 $ Amount: num  0.3 0 0 0 0 2.7 7.1 14 12.6 11.1 ...

> tbl <- xtabs(~Year+Month, rain, subset=Amount > 0.01)
> tbl
  Month
Year1  2  3  4  5  6  7  8  9 10 11 12
  1960 24 15  2 12 19 22 18 24 22 20 30 29
  1961 26  9 10 18 18 11 18 14 24 28 30 31
  1962 22 14 19  2 18 19 27 26 26 29 15 28
  1963 27 17 15  4  9 23 16 24 19 28 30 22
  1964 15 25  9 13 19 14 23 20 24 30 25 27
  1965 13 21 12 10 21 24 22 21 28 23 28 31

If you want the month names:

> mnt <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "July", "Aug", "Sep", "Oct", "Nov", "Dec")
> dimnames(tbl)$Month <- mnt
> tbl
  Month
Year   Jan Feb Mar Apr May Jun July Aug Sep Oct Nov Dec
  1960  24  15   2  12  19  22   18  24  22  20  30  29
  1961  26   9  10  18  18  11   18  14  24  28  30  31
  1962  22  14  19   2  18  19   27  26  26  29  15  28
  1963  27  17  15   4   9  23   16  24  19  28  30  22
  1964  15  25   9  13  19  14   23  20  24  30  25  27
  1965  13  21  12  10  21  24   22  21  28  23  28  31

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352

From: smart hendsome [mailto:putra_autum...@yahoo.com] 
Sent: Wednesday, September 30, 2015 9:24 PM
To: David L Carlson
Subject: Re: [R] Counting number of rain

Hi David,

Thanks for your reply, this is my data using dput;

structure(list(Year = c(1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961

Re: [R] Counting number of rain

2015-10-01 Thread Rolf Turner

On 02/10/15 03:45, David L Carlson wrote:




If you want the month names:


mnt <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun",

+ "July", "Aug", "Sep", "Oct", "Nov", "Dec")

dimnames(tbl)$Month <- mnt




Unnecessary typing; there is a built-in data set "month.abb" (in the
"base" package) that is identical to your "mnt".

Difficult (nearly impossible!) to find, but, if you can't quite remember 
the name!  I *knew* I'd seen it, so I persisted and eventually tracked 
it down.


Strangely ??month or help.search("month") yield no trace of it.  Pages 
and pages of (useless!) output but no sign of "month.abb" (nor of 
"month.name" which gives the unabbreviated month names).


Can anyone explain to me why "??" and help.search() are of no help here?

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@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.


Re: [R] Counting number of rain

2015-10-01 Thread peter dalgaard

> On 01 Oct 2015, at 23:04 , Rolf Turner  wrote:
> 
> On 02/10/15 03:45, David L Carlson wrote:
> 
> 
> 
>> If you want the month names:
>> 
>>> mnt <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
>> + "July", "Aug", "Sep", "Oct", "Nov", "Dec")
>>> dimnames(tbl)$Month <- mnt
> 
> 
> 
> Unnecessary typing; there is a built-in data set "month.abb" (in the
> "base" package) that is identical to your "mnt".
> 
> Difficult (nearly impossible!) to find, but, if you can't quite remember the 
> name!  I *knew* I'd seen it, so I persisted and eventually tracked it down.
> 
> Strangely ??month or help.search("month") yield no trace of it.  Pages and 
> pages of (useless!) output but no sign of "month.abb" (nor of "month.name" 
> which gives the unabbreviated month names).
> 
> Can anyone explain to me why "??" and help.search() are of no help here?

Umm,

---
Help files with alias or concept or title matching ‘month’ using fuzzy
matching:


base::Constants Built-in Constants
  Aliases: month.abb, month.name

---

Also, entering "month" gives the completions

> month
month.abb  monthplot  months.Date
month.name months months.POSIXt  

-pd

> 
> cheers,
> 
> Rolf Turner
> 
> -- 
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
> 
> __
> R-help@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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@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.

Re: [R] Counting number of rain

2015-10-01 Thread Rolf Turner

On 02/10/15 10:54, peter dalgaard wrote:


On 01 Oct 2015, at 23:04 , Rolf Turner 
wrote:

On 02/10/15 03:45, David L Carlson wrote:




If you want the month names:


mnt <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun",

+ "July", "Aug", "Sep", "Oct", "Nov", "Dec")

dimnames(tbl)$Month <- mnt




Unnecessary typing; there is a built-in data set "month.abb" (in
the "base" package) that is identical to your "mnt".

Difficult (nearly impossible!) to find, but, if you can't quite
remember the name!  I *knew* I'd seen it, so I persisted and
eventually tracked it down.

Strangely ??month or help.search("month") yield no trace of it.
Pages and pages of (useless!) output but no sign of "month.abb"
(nor of "month.name" which gives the unabbreviated month names).

Can anyone explain to me why "??" and help.search() are of no help
here?


Umm,

--- Help files with alias or concept or title matching ‘month’
using fuzzy matching:


base::Constants Built-in Constants Aliases: month.abb,
month.name  ---


Hmm. When I did ??month I got a completely different display. It
contained *absolutely no* mention of month.abb. That *seems* to be
because I have help_type set to "html". When I re-set help_type to
"text", I get a display like unto the one that you obtained (and it does 
indeed lead one to month.abb).


It seems to me ver' strange that one gets a different collection of
information under help_type="text" than one does under help_type="html".
If I were me, I would classify this as a bug.


Also, entering "month" gives the completions


month

month.abb  monthplot  months.Date month.name months
months.POSIXt


Yes, I eventually managed to come up with this trick as well.  But that 
is not really relevant to the phenomenon that "??" or help.search() 
don't work effectively, or at least not consistently (the effectiveness 
appearing to depend --- for some bizarre reason --- on the value of 
help_type).


cheers,

Rolf

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?

Or is my recollection an illusion brought on by advancing senility?

R.

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@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.

Re: [R] Counting number of rain

2015-10-01 Thread David Winsemius

On Oct 1, 2015, at 6:22 PM, Rolf Turner wrote:

> On 02/10/15 10:54, peter dalgaard wrote:
> 
>>> On 01 Oct 2015, at 23:04 , Rolf Turner 
>>> wrote:
>>> 
>>> On 02/10/15 03:45, David L Carlson wrote:
>>> 
>>> 
>>> 
 If you want the month names:
 
> mnt <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
 + "July", "Aug", "Sep", "Oct", "Nov", "Dec")
> dimnames(tbl)$Month <- mnt
>>> 
>>> 
>>> 
>>> Unnecessary typing; there is a built-in data set "month.abb" (in
>>> the "base" package) that is identical to your "mnt".
>>> 
>>> Difficult (nearly impossible!) to find, but, if you can't quite
>>> remember the name!  I *knew* I'd seen it, so I persisted and
>>> eventually tracked it down.
>>> 
>>> Strangely ??month or help.search("month") yield no trace of it.
>>> Pages and pages of (useless!) output but no sign of "month.abb"
>>> (nor of "month.name" which gives the unabbreviated month names).
>>> 
>>> Can anyone explain to me why "??" and help.search() are of no help
>>> here?
>> 
>> Umm,
>> 
>> --- Help files with alias or concept or title matching ‘month’
>> using fuzzy matching:
>> 
>> 
>> base::Constants Built-in Constants Aliases: month.abb,
>> month.name  ---
> 
> Hmm. When I did ??month I got a completely different display. It
> contained *absolutely no* mention of month.abb. That *seems* to be
> because I have help_type set to "html". When I re-set help_type to
> "text", I get a display like unto the one that you obtained (and it does 
> indeed lead one to month.abb).
> 
> It seems to me ver' strange that one gets a different collection of
> information under help_type="text" than one does under help_type="html".
> If I were me, I would classify this as a bug.
> 
>> Also, entering "month" gives the completions
>> 
>>> month
>> month.abb  monthplot  months.Date month.name months
>> months.POSIXt
> 
> Yes, I eventually managed to come up with this trick as well.  But that is 
> not really relevant to the phenomenon that "??" or help.search() don't work 
> effectively, or at least not consistently (the effectiveness appearing to 
> depend --- for some bizarre reason --- on the value of help_type).
> 
> cheers,
> 
> Rolf
> 
> 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" 


> Or is my recollection an illusion brought on by advancing senility?
> 
> R.
> 
> -- 
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
> 
> __
> R-help@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

__
R-help@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.


Re: [R] Counting number of rain

2015-10-01 Thread David Winsemius

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

> On 02/10/15 15:47, David Winsemius wrote:
> 
> 
> 
>> 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"
> 
> 
> 
> 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, "-00-00")) 
origin <- as.Date("-01-01", ...) - 1
as.Date(origin, ...) + x
}


-- 

David Winsemius
Alameda, CA, USA

__
R-help@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.


Re: [R] Counting number of rain

2015-10-01 Thread Rolf Turner

On 02/10/15 15:47, David Winsemius wrote:




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"




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*???

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@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] Counting number of rain

2015-09-08 Thread smart hendsome via R-help
Hello R-users,
I want to ask how to count the number of daily rain data.  My data as below:
 Year Month Day Amount 1901 1 1 0 1901 1 2 3 1901 1 3 0 1901 1 4 0.5 1901 1 5 0 
1901 1 6 0  1901 1 7 0.3 1901 1 8 0 1901 1 9 0 1901 1 10 0 1901 1 11 0.5 1901 1 
12 1.8 1901 1 13 0 1901 1 14 0 1901 1 15 2.5 1901 1 16 0 1901 1 17 0 1901 1 18 
0 1901 1 19 0 1901 1 20 0 1901 1 21 0 1901 1 22 0 1901 1 23 0 1901 1 24 0 1901 
1 25 0 1901 1 26 16.5 1901 1 27 0.3 1901 1 28 0 1901 1 29 0 1901 1 30 0 1901 1 
31 0 1901 2 1 0 1901 2 2 0 1901 2 3 0 1901 2 4 0 1901 2 5 0 1901 2 6 0 1901 2 7 
0 1901 2 8 0.3 1901 2 9 0 1901 2 10 0 1901 2 11 0 1901 2 12 1 1901 2 13 0.3 
1901 2 14 0 1901 2 15 0 1901 2 16 0 1901 2 17 0 1901 2 18 0 1901 2 19 0 1901 2 
20 0 1901 2 21 0 1901 2 22 0 1901 2 23 0.3 1901 2 24 0 1901 2 25 0 1901 2 26 
0.3 1901 2 27 0 1901 2 28 0 1901 3 1 0 1901 3 2 0.8 1901 3 3 2.3 1901 3 4 0 
1901 3 5 0 1901 3 6 0 1901 3 7 0 1901 3 8 0 1901 3 9 0 1901 3 10 2 1901 3 11 0 
1901 3 12 0 1901 3 13 0 1901 3 14 0 1901 3 15 0 1901 3 16 0 1901 3 17 0 1901 3 
18 0 1901 3 19 0 1901 3 20 0 1901 3 21 0 1901 3 22 1.5 1901 3 23 1.3 1901 3 24 
0 1901 3 25 0 1901 3 26 0 1901 3 27 0 1901 3 28 0.3 1901 3 29 0.3  1901 3 30 
4.6 1901 3 31 0 1901 4 1 0 1901 4 2 4.6 1901 4 3 30.7 1901 4 4 0 1901 4 5 0 
1901 4 6 0 1901 4 7 0 1901 4 8 0 1901 4 9 0 1901 4 10 0 1901 4 11 0 1901 4 12 0 
1901 4 13 0 1901 4 14 0 1901 4 15 0.3 1901 4 16 1.3 1901 4 17 0 1901 4 18 0 
1901 4 19 0.3 1901 4 20 1 1901 4 21 9.4 1901 4 22 0.5 1901 4 23 0.3 1901 4 24 0 
1901 4 25 0 1901 4 26 0 1901 4 27 0 1901 4 28 0 1901 4 29 0 1901 4 30 0 1901 5 
1 0 1901 5 2 0 1901 5 3 0 1901 5 4 0 1901 5 5 0 1901  5 6 0 1901 5 7 0 1901 5 8 
0.5 1901 5 9 2.3 1901 5 10 0.3 1901 5 11 0 1901 5 12 0 1901 5 13 0 1901 5 14 0 
1901 5 15 0 1901 5 16 0 1901 5 17 0 1901 5 18 0 1901 5 19 0 1901 5 20 0 1901 5 
21 0.5 1901 5 22 0 1901 5 23 0 1901 5 24 0 1901 5 25 0 1901 5 26 4.8 1901 5 27 
10.9 1901 5 28 3.6 1901 5 29 0 1901 5 30 0 1901 5 31 5.1 1901 6 1 0.5 1901 6 2 
0 1901 6 3 2 1901 6 4 0  1901 6 5 10.2 1901 6 6 33.3 1901 6 7 0.3 1901 6 8 0 
1901 6 9 0 1901 6 10 0.5 1901 6 11 0.5 1901 6 12 0.3 1901 6 13 2.8 1901 6 14 
5.6 1901 6 15 0.3 1901 6 16 6.6 1901 6 17 14.2 1901 6 18 4.8  1901 6 19 8.4 
1901 6 20 1.8 1901 6 21 1.8 1901 6 22 0.3 1901 6 23 8.6 1901 6 24 0 1901 6 25 0 
 1901 6 26 0 1901 6 27 0 1901 6 28 0 1901 6 29 0 1901 6 30 0 1901 7 1 0 1901 7 
2 0 1901 7 3 0 1901 7 4 0 1901 7 5 1 1901 7 6 0.5 1901 7 7 0.3 1901 7 8 0.3 
1901 7 9 6.1 1901 7 10 0.3  1901 7 11 1.5 1901 7 12 0 1901 7 13 1.5 1901 7 14 
0.3 1901 7 15 3.3 1901 7 16 2.3 1901 7 17 0.5  1901 7 18 0 1901 7 19 0 1901 7 
20 0 1901 7 21 1.8 1901 7 22 0 1901 7 23 1 1901 7 24 0.3 1901  7 25 0.3 1901 7 
26 1.3 1901 7 27 17 1901 7 28 6.6 1901 7 29 6.1 1901 7 30 0.5 1901 7 31 0.3 
1901 8 1 0 1901 8 2 0 1901 8 3 0 1901 8 4 0 1901 8 5 0 1901 8 6 3.3 1901 8 7 
4.1 1901 8 8 0.3  1901 8 9 0 1901 8 10 0 1901 8 11 0 1901 8 12 0 1901 8 13 0 
1901 8 14 0 1901 8 15 0 1901 8 16 0 1901 8 17 0.5 1901 8 18 0 1901 8 19 0 1901 
8 20 0 1901 8 21 0 1901 8 22 0 1901 8 23 0.3 1901 8 24 1 1901 8 25 0 1901 8 26 
0 1901 8 27 10.2 1901 8 28 1.5 1901 8 29 0.5 1901 8 30 1.3  1901 8 31 0 1901 9 
1 0 1901 9 2 3 1901 9 3 1 1901 9 4 0.5 1901 9 5 0.3 1901 9 6 0 1901 9 7 0 1901 
9 8 2.3 1901 9 9 0.3 1901 9 10 0 1901 9 11 0 1901 9 12 0 1901 9 13 0 1901 9 14 
0  1901 9 15 0 1901 9 16 0 1901 9 17 0 1901 9 18 1.8 1901 9 19 8.1 1901 9 20 
0.3 1901 9 21 5.8 1901 9 22 4.1 1901 9 23 0.3 1901 9 24 1.8 1901 9 25 0 1901 9 
26 0 1901 9 27 0 1901 9 28 0 1901  9 29 1.8 1901 9 30 0.8 1901 10 1 0 1901 10 2 
0 1901 10 3 0 1901 10 4 0 1901 10 5 0.3 1901 10 6 0 1901 10 7 0 1901 10 8 0 
1901 10 9 0 1901 10 10 0 1901 10 11 0.3 1901 10 12 3.8 1901 10 13 0.4 1901 10 
14 9 1901 10 15 2 1901 10 16 1 1901 10 17 0 1901 10 18 0 1901 10 19 0 1901 10 
20 0.3 1901 10 21 0 1901 10 22 0 1901 10 23 0 1901 10 24 0 1901 10 25 0 1901 10 
26 0 1901 10 27 14.5  1901 10 28 6.4 1901 10 29 0.8 1901 10 30 0 1901 10 31 0 
1901 11 1 0 1901 11 2 0 1901 11 3 0  1901 11 4 0 1901 11 5 0 1901 11 6 0 1901 
11 7 0 1901 11 8 0 1901 11 9 0 1901 11 10 0 1901 11 11 0 1901 11 12 5.1 1901 11 
13 0.3 1901 11 14 5.8 1901 11 15 0 1901 11 16 0 1901 11 17 1 1901 11 18 0.5 
1901 11 19 0 1901 11 20 0 1901 11 21 0 1901 11 22 0 1901 11 23 0 1901 11 24 0 
1901 11 25 0.3 1901 11 26 0 1901 11 27 0 1901 11 28 0 1901 11 29 0 1901 11 30 
3.3 1901 12 1 0 1901 12 2 0 1901 12 3 0 1901 12 4 0 1901 12 5 0 1901 12 6 0 
1901 12 7 0 1901 12 8 0 1901 12 9 0 1901 12 10 0 1901 12 11 0 1901 12 12 0 1901 
12 13 0 1901 12 14 0 1901 12 15 0 1901 12 16 0 1901 12 17 0 1901 12 18 0 1901 
12 19 0 1901 12 20 0 1901 12 21 6.1 1901 12 22 5.6 1901 12 23 0 1901 12 24 0 
1901 12 25 0 1901 12 26 0 1901 12 27 0 1901 12 28 0 1901 12 29 0 1901 12 30 0 
1901 12 31 9.9 1902 1 1 0 1902 1 2 0 1902 1 3 0 1902 1 4 4.1 1902 1 5 0 1902 1 
6 0 1902 1 7 0 1902 1 8 0 1902 1 9 2.5 1902 1 10 0 1902 1 11 0 1902 1 12 0 1902 
1 13 0.3 1902 1 14 0 1902 1 15 0 1902 1 16 0 1902 1 17 0 1902 1 18 0 

Re: [R] Counting number of rain

2015-09-08 Thread John Kane
Assuming your data is already in R format please sent it  dput() format.  See 
?dput or 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
 and http://adv-r.had.co.nz/Reproducibility.html for more details.

John Kane
Kingston ON Canada


> -Original Message-
> From: r-help@r-project.org
> Sent: Tue, 8 Sep 2015 06:58:58 + (UTC)
> To: r-help@r-project.org
> Subject: [R] Counting number of rain
> 
> Hello R-users,
> I want to ask how to count the number of daily rain data.  My data as
> below:
>  Year Month Day Amount 1901 1 1 0 1901 1 2 3 1901 1 3 0 1901 1 4 0.5 1901
> 1 5 0 1901 1 6 0  1901 1 7 0.3 1901 1 8 0 1901 1 9 0 1901 1 10 0 1901 1
> 11 0.5 1901 1 12 1.8 1901 1 13 0 1901 1 14 0 1901 1 15 2.5 1901 1 16 0
> 1901 1 17 0 1901 1 18 0 1901 1 19 0 1901 1 20 0 1901 1 21 0 1901 1 22 0
> 1901 1 23 0 1901 1 24 0 1901 1 25 0 1901 1 26 16.5 1901 1 27 0.3 1901 1
> 28 0 1901 1 29 0 1901 1 30 0 1901 1 31 0 1901 2 1 0 1901 2 2 0 1901 2 3 0
> 1901 2 4 0 1901 2 5 0 1901 2 6 0 1901 2 7 0 1901 2 8 0.3 1901 2 9 0 1901
> 2 10 0 1901 2 11 0 1901 2 12 1 1901 2 13 0.3 1901 2 14 0 1901 2 15 0 1901
> 2 16 0 1901 2 17 0 1901 2 18 0 1901 2 19 0 1901 2 20 0 1901 2 21 0 1901 2
> 22 0 1901 2 23 0.3 1901 2 24 0 1901 2 25 0 1901 2 26 0.3 1901 2 27 0 1901
> 2 28 0 1901 3 1 0 1901 3 2 0.8 1901 3 3 2.3 1901 3 4 0 1901 3 5 0 1901 3
> 6 0 1901 3 7 0 1901 3 8 0 1901 3 9 0 1901 3 10 2 1901 3 11 0 1901 3 12 0
> 1901 3 13 0 1901 3 14 0 1901 3 15 0 1901 3 16 0 1901 3 17 0 1901 3 18 0
> 1901 3 19 0 1901 3 20 0 1901 3 21 0 1901 3 22 1.5 1901 3 23 1.3 1901 3 24
> 0 1901 3 25 0 1901 3 26 0 1901 3 27 0 1901 3 28 0.3 1901 3 29 0.3  1901 3
> 30 4.6 1901 3 31 0 1901 4 1 0 1901 4 2 4.6 1901 4 3 30.7 1901 4 4 0 1901
> 4 5 0 1901 4 6 0 1901 4 7 0 1901 4 8 0 1901 4 9 0 1901 4 10 0 1901 4 11 0
> 1901 4 12 0 1901 4 13 0 1901 4 14 0 1901 4 15 0.3 1901 4 16 1.3 1901 4 17
> 0 1901 4 18 0 1901 4 19 0.3 1901 4 20 1 1901 4 21 9.4 1901 4 22 0.5 1901
> 4 23 0.3 1901 4 24 0 1901 4 25 0 1901 4 26 0 1901 4 27 0 1901 4 28 0 1901
> 4 29 0 1901 4 30 0 1901 5 1 0 1901 5 2 0 1901 5 3 0 1901 5 4 0 1901 5 5 0
> 1901  5 6 0 1901 5 7 0 1901 5 8 0.5 1901 5 9 2.3 1901 5 10 0.3 1901 5 11
> 0 1901 5 12 0 1901 5 13 0 1901 5 14 0 1901 5 15 0 1901 5 16 0 1901 5 17 0
> 1901 5 18 0 1901 5 19 0 1901 5 20 0 1901 5 21 0.5 1901 5 22 0 1901 5 23 0
> 1901 5 24 0 1901 5 25 0 1901 5 26 4.8 1901 5 27 10.9 1901 5 28 3.6 1901 5
> 29 0 1901 5 30 0 1901 5 31 5.1 1901 6 1 0.5 1901 6 2 0 1901 6 3 2 1901 6
> 4 0  1901 6 5 10.2 1901 6 6 33.3 1901 6 7 0.3 1901 6 8 0 1901 6 9 0 1901
> 6 10 0.5 1901 6 11 0.5 1901 6 12 0.3 1901 6 13 2.8 1901 6 14 5.6 1901 6
> 15 0.3 1901 6 16 6.6 1901 6 17 14.2 1901 6 18 4.8  1901 6 19 8.4 1901 6
> 20 1.8 1901 6 21 1.8 1901 6 22 0.3 1901 6 23 8.6 1901 6 24 0 1901 6 25 0
> 1901 6 26 0 1901 6 27 0 1901 6 28 0 1901 6 29 0 1901 6 30 0 1901 7 1 0
> 1901 7 2 0 1901 7 3 0 1901 7 4 0 1901 7 5 1 1901 7 6 0.5 1901 7 7 0.3
> 1901 7 8 0.3 1901 7 9 6.1 1901 7 10 0.3  1901 7 11 1.5 1901 7 12 0 1901 7
> 13 1.5 1901 7 14 0.3 1901 7 15 3.3 1901 7 16 2.3 1901 7 17 0.5  1901 7 18
> 0 1901 7 19 0 1901 7 20 0 1901 7 21 1.8 1901 7 22 0 1901 7 23 1 1901 7 24
> 0.3 1901  7 25 0.3 1901 7 26 1.3 1901 7 27 17 1901 7 28 6.6 1901 7 29 6.1
> 1901 7 30 0.5 1901 7 31 0.3 1901 8 1 0 1901 8 2 0 1901 8 3 0 1901 8 4 0
> 1901 8 5 0 1901 8 6 3.3 1901 8 7 4.1 1901 8 8 0.3  1901 8 9 0 1901 8 10 0
> 1901 8 11 0 1901 8 12 0 1901 8 13 0 1901 8 14 0 1901 8 15 0 1901 8 16 0
> 1901 8 17 0.5 1901 8 18 0 1901 8 19 0 1901 8 20 0 1901 8 21 0 1901 8 22 0
> 1901 8 23 0.3 1901 8 24 1 1901 8 25 0 1901 8 26 0 1901 8 27 10.2 1901 8
> 28 1.5 1901 8 29 0.5 1901 8 30 1.3  1901 8 31 0 1901 9 1 0 1901 9 2 3
> 1901 9 3 1 1901 9 4 0.5 1901 9 5 0.3 1901 9 6 0 1901 9 7 0 1901 9 8 2.3
> 1901 9 9 0.3 1901 9 10 0 1901 9 11 0 1901 9 12 0 1901 9 13 0 1901 9 14 0
> 1901 9 15 0 1901 9 16 0 1901 9 17 0 1901 9 18 1.8 1901 9 19 8.1 1901 9 20
> 0.3 1901 9 21 5.8 1901 9 22 4.1 1901 9 23 0.3 1901 9 24 1.8 1901 9 25 0
> 1901 9 26 0 1901 9 27 0 1901 9 28 0 1901  9 29 1.8 1901 9 30 0.8 1901 10
> 1 0 1901 10 2 0 1901 10 3 0 1901 10 4 0 1901 10 5 0.3 1901 10 6 0 1901 10
> 7 0 1901 10 8 0 1901 10 9 0 1901 10 10 0 1901 10 11 0.3 1901 10 12 3.8
> 1901 10 13 0.4 1901 10 14 9 1901 10 15 2 1901 10 16 1 1901 10 17 0 1901
> 10 18 0 1901 10 19 0 1901 10 20 0.3 1901 10 21 0 1901 10 22 0 1901 10 23
> 0 1901 10 24 0 1901 10 25 0 1901 10 26 0 1901 10 27 14.5  1901 10 28 6.4
> 1901 10 29 0.8 1901 10 30 0 1901 10 31 0 1901 11 1 0 1901 11 2 0 1901 11
> 3 0  1901 11 4 0 1901 11 5 0 1901 11 6 0 1901 11 7 0 1901 11 8 0 1901 11
> 9 0 1901 11 10 0 1901 11 11 0 1901 11 12 5.1 1901 11 13 0.3 1901 11 14
> 5.8 1901 11 15 0 1901 11 16 0 1901 11 17 1 1901 11 18 0.5 1901 11 19 0
> 1901 11 20 0 1901 11 21 0 1901 11 22 0 1901 11 23 0 1901 11 

Re: [R] Counting number of rain

2015-09-08 Thread Dan D
Try the following:

## step 1: write raw data to an array
junk<-scan('clipboard') 
# entering the numbers (not the 'year' etc. labels) into R as a vector after

junk<-t(array(junk,dim=c(4,length(junk)/4))) 
# convert the vector into a 2-d array with 4 columns (year, month, day,
amount)

## step 2: create a dataframe to store and display the results
nyr<-length(unique(junk[,1]))
ans<-data.frame(array(dim=c(nyr,12))) # a dataframe for storing the results
names(ans)<-c('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')
yrs<-sort(unique(junk[,1]))
row.names(ans)<-yrs

# step 3: calculate
for (yi in 1:nyr){ # loop through the years...
  for (mi in 1:12){ # ...and the months
 ans[yi,mi]<-sum(junk[junk[,1]==yrs[yi] & junk[,2]==mi,4]>0.01) #
count the rainy days by
 # first subsetting the junk array by rows that match the given year and
month and sum
  }
}

Does that help?

- Dan



--
View this message in context: 
http://r.789695.n4.nabble.com/Counting-number-of-rain-tp4712007p4712011.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.