[R] [R-pkgs] listcompr: list comprehension for R

2021-01-16 Thread Patrick Roocks

Dear R users,

I am happy to announce the first version of listcompr which is on CRAN 
now. listcompr is a "syntactic sugar" approach to generate lists, 
vectors and data frames with list comprehension.


Some examples are shown on the readme page on the github repository: 
https://github.com/patrickroocks/listcompr


I hope this is useful for some of you.

All the best,

Patrick

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] Converting "day of year" to "year", "month" and "day"

2021-01-16 Thread peter dalgaard
Something like this?

> as.Date(ISOdate(1998,1,1))+(1:100)-1
  [1] "1998-01-01" "1998-01-02" "1998-01-03" "1998-01-04" "1998-01-05"
  [6] "1998-01-06" "1998-01-07" "1998-01-08" "1998-01-09" "1998-01-10"
 [11] "1998-01-11" "1998-01-12" "1998-01-13" "1998-01-14" "1998-01-15"
 [16] "1998-01-16" "1998-01-17" "1998-01-18" "1998-01-19" "1998-01-20"
 [21] "1998-01-21" "1998-01-22" "1998-01-23" "1998-01-24" "1998-01-25"
 [26] "1998-01-26" "1998-01-27" "1998-01-28" "1998-01-29" "1998-01-30"
 [31] "1998-01-31" "1998-02-01" "1998-02-02" "1998-02-03" "1998-02-04"
 [36] "1998-02-05" "1998-02-06" "1998-02-07" "1998-02-08" "1998-02-09"
 [41] "1998-02-10" "1998-02-11" "1998-02-12" "1998-02-13" "1998-02-14"
 [46] "1998-02-15" "1998-02-16" "1998-02-17" "1998-02-18" "1998-02-19"
 [51] "1998-02-20" "1998-02-21" "1998-02-22" "1998-02-23" "1998-02-24"
 [56] "1998-02-25" "1998-02-26" "1998-02-27" "1998-02-28" "1998-03-01"
 [61] "1998-03-02" "1998-03-03" "1998-03-04" "1998-03-05" "1998-03-06"
 [66] "1998-03-07" "1998-03-08" "1998-03-09" "1998-03-10" "1998-03-11"
 [71] "1998-03-12" "1998-03-13" "1998-03-14" "1998-03-15" "1998-03-16"
 [76] "1998-03-17" "1998-03-18" "1998-03-19" "1998-03-20" "1998-03-21"
 [81] "1998-03-22" "1998-03-23" "1998-03-24" "1998-03-25" "1998-03-26"
 [86] "1998-03-27" "1998-03-28" "1998-03-29" "1998-03-30" "1998-03-31"
 [91] "1998-04-01" "1998-04-02" "1998-04-03" "1998-04-04" "1998-04-05"
 [96] "1998-04-06" "1998-04-07" "1998-04-08" "1998-04-09" "1998-04-10"

Or, if you want month numbers and day of month as numerics:

> as.POSIXlt(as.Date(ISOdate(1998,1,1))+(1:100)-1)$mon
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1
 [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
 [75] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3
> as.POSIXlt(as.Date(ISOdate(1998,1,1))+(1:100)-1)$mday
  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 [26] 26 27 28 29 30 31  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
 [51] 20 21 22 23 24 25 26 27 28  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
 [76] 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  1  2  3  4  5  6  7  8  9 10

-pd

> On 16 Jan 2021, at 07:48 , Jibrin Alhassan  wrote:
> 
> Hi Barradas
> Sorry for the delay. Below is a section of my data. I have up to 1826
> covering 1998 to 2002
> year   day Hr SWS
> 1998   1  0  344.
> 1998   2  0  346.
> 1998   3  0  356.
> 1998   4  0  332.
> 1998   5  0  302.
> 1998   6  0  329.
> 1998   7  0  395.
> 1998   8  0  359.
> 1998   9  0  471.
> 1998  10  0  392.
> 1998  11  0  346.
> 1998  12  0  387.
> 1998  13  0  393.
> 1998  14  0  367.
> 1998  15  0  320.
> 1998  16  0  309.
> 1998  17  0  341.
> 1998  18  0  329.
> 1998  19  0  322.
> 1998  20  0  429.
> 1998  21  0  433.
> 1998  22  0  398.
> 1998  23  0  393.
> 1998  24  0  393.
> 1998  25  0  423.
> 1998  26  0  426.
> 1998  27  0  429.
> 1998  28  0  386.
> 1998  29  0  381.
> 1998  30  0  375.
> 1998  31  0  365.
> 1998  32  0  450.
> 1998  33  0  381.
> 1998  34  0  316.
> 1998  35  0  351.
> 1998  36  0  306.
> 1998  37  0  312.
> 1998  38  0  320.
> 1998  39  0  339.
> 1998  40  0  395.
> 1998  41  0  429.
> 1998  42  0  479.
> 1998  43  0  495.
> 1998  44  0  407.
> 1998  45  0  358.
> 1998  46  0  360.
> 1998  47  0  382.
> 1998  48  0  394.
> 1998  49  0  393.
> 1998  50  0  435.
> 1998  51  0  408.
> 1998  52  0  360.
> 1998  53  0  372.
> 1998  54  0  376.
> 1998  55  0  379.
> 1998  56  0  361.
> 1998  57  0  333.
> 1998  58  0  321.
> 1998  59  0  344.
> 1998  60  0  412.
> 1998  61  0  428.
> 1998  62  0  401.
> 1998  63  0  369.
> 1998  64  0  343.
> 1998  65  0  330.
> 1998  66  0  317.
> 1998  67  0  296.
> 1998  68  0  282.
> 1998  69  0  404.
> 1998  70  0  530.
> 1998  71  0  525.
> 1998  72  0  484.
> 1998  73  0  430.
> 1998  74  0  388.
> 1998  75  0  347.
> 1998  76  0  337.
> 1998  77  0  342.
> 1998  78  0  305.
> 1998  79  0  329.
> 1998  80  0  420.
> 1998  81  0  564.
> 1998  82  0  483.
> 1998  83  0  385.
> 1998  84  0  393.
> 1998  85  0  437.
> 1998  86  0  441.
> 1998  87  0  434.
> 1998  88  0  471.
> 1998  89  0  429.
> 1998  90  0  412.
> 1998  91  0  370.
> 1998  92  0  326.
> 1998  93  0  357.
> 1998  94  0  338.
> 1998  95  0  380.
> 1998  96  0  339.
> 1998  97  0  312.
> 1998  98  0  313.
> 1998  99  0  327.
> 1998 100  0  362.
> 1998 101  0  358.
> 1998 102  0  387.
> 1998 103  0  397.
> 1998 104  0  375.
> 1998 105  0  350.
> 1998 106  0  357.
> 1998 107  0  472.
> 1998 108  0  526.
> 1998 109  0  396.
> 1998 110  0  374.
> 1998 111  0  376.
> 1998 112  0  355.
> 1998 113  0  343.
> 1998 114  0  425.
> 1998 115  0  426.
> 1998 116  0  479.
> 1998 117  0  469.
> 1998 118  0  425.
> 1998 119  0  344.
> 1998 120  0  341.
> 1998 121  0  426.
> 1998 122  0  601.
> 1998 123  0  476.
> 1998 124  0  670.
> 1998 125  0  585.
> 1998 126  0  496.
> 1998 127  0  479.
> 1998 128  0  569.
> 1998 129  0  531.
> 1998 130  0  489.
> 1998 131