[R] Number of days in each month
Chuck Cleland
ccleland at optonline.net
Tue Aug 7 15:07:56 CEST 2007
Lauri Nikkinen wrote:
> Hi R-users,
>
> What is the best way to achieve a table which contains all days and months
> between years 2007-2020? I would like to calculate number of days in each
> month within those years (to data frame).
>
> Regards,
>
> Lauri
How about this?
X <- seq(ISOdate(2007,1,1), ISOdate(2020,12,31), by=60*60*24)
mytab <- table(substring(X, 3, 4), substring(X, 6, 7))
mytab
01 02 03 04 05 06 07 08 09 10 11 12
07 31 28 31 30 31 30 31 31 30 31 30 31
08 31 29 31 30 31 30 31 31 30 31 30 31
09 31 28 31 30 31 30 31 31 30 31 30 31
10 31 28 31 30 31 30 31 31 30 31 30 31
11 31 28 31 30 31 30 31 31 30 31 30 31
12 31 29 31 30 31 30 31 31 30 31 30 31
13 31 28 31 30 31 30 31 31 30 31 30 31
14 31 28 31 30 31 30 31 31 30 31 30 31
15 31 28 31 30 31 30 31 31 30 31 30 31
16 31 29 31 30 31 30 31 31 30 31 30 31
17 31 28 31 30 31 30 31 31 30 31 30 31
18 31 28 31 30 31 30 31 31 30 31 30 31
19 31 28 31 30 31 30 31 31 30 31 30 31
20 31 29 31 30 31 30 31 31 30 31 30 31
head(as.data.frame(mytab))
Var1 Var2 Freq
1 07 01 31
2 08 01 31
3 09 01 31
4 10 01 31
5 11 01 31
6 12 01 31
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list