Skip to contents

Calculates average of variation of time series. (contain but not limited to: average daily variation, average monthly variation, average annual variation)

Usage

avri(
  df,
  bkip = NULL,
  mode = "recipes",
  value = "day",
  st = NULL,
  et = NULL,
  na.rm = TRUE,
  digits = 2,
  wind = FALSE,
  coliws = 2,
  coliwd = 3,
  sn = FALSE
)

Arguments

df

dataframe of time series.

bkip

the basic time reslution for average variation, such as '1 hour'. If mode "custom" is selected, do not need to enter bkip.

mode

for calculating cycles: "recipes", "ncycle", "custom". "recipes" means using internal setting for calculation. "ncycle" means setting number of items for per cycle. "custom" means using 1 column in dataframe as a list of grouping elements for calculation.

value

for detail setting of mode. Possible values for "recipes" are "day", "week", "month", year". "day" equals to 24 (hours) values in 1 day. "week" equals to 7 (days) values in 1 week. "month" equals to 31 (days) values in 1 month. "year" equals to 12 (months) values in 1 year. values for "ncycle" is a number representing number of items in per cycle. values for "custom" is a number representing column index in dataframe.

st

start time of resampling. The default value is the fisrt value of datetime column.

et

end time of resampling. The default value is the last value of datetime column.

na.rm

logical value. Remove NA value or not?

digits

numeric value, digits for result dataframe.

wind

logical value. if TRUE, please set coliwd, coliws.

coliws

numeric value, column index of wind speed in dataframe.

coliwd

numeric value, column index of wind direction (degree) in dataframe.

sn

logical value. if TRUE, the results will be presented by scientific notation (string).

Value

a data frame which contains both the average variations and the standard deviations. Note that when the pattern USES "ncycle" or "custom", the start time determines the start time of the first element in the average variation. For example, if the first timestamp of data is "2010-05-01 12:00:00", the resolution is 1 hour, the mode is "ncycle", and the value is 24, then the result represents diurnal variation starting from 12 o'clock.

Details

If you have wind data (wind speed, and wind direction in dgree), please set 'wind' as 'TRUE', and set values for 'coliwd' and 'coliws'.

Examples

avri(met, bkip = "1 hour", mode = "recipes", value = "day",
st = "2017-05-01 00:00:00", wind = TRUE, coliws = 4, coliwd = 5)
#> Joining, by = "temp_datetime"
#>    hour of day  TEM_ave  HUM_ave    WS_ave    WD_ave    TEM_sd    HUM_sd
#> 1            0 19.15833 83.96667 1.4811489  87.41851 2.1581483 13.598800
#> 2            1 19.29167 82.55667 1.5862124  98.19083 2.3189063 17.386062
#> 3            2 19.21167 82.05833 1.7431234  91.18130 2.2133167 16.084012
#> 4            3 18.77167 82.04333 2.2367487  93.83197 1.6347422 13.617010
#> 5            4 18.58167 82.88000 2.2840369 106.44643 1.5452593 11.451954
#> 6            5 18.56875 83.03958 2.1493396 100.41436 1.7181409 15.153850
#> 7            6 20.06875 76.82083 2.6610319  88.70396 0.8233956 17.287603
#> 8            7 21.79167 66.00833 2.8604533 100.63802 0.6042672 12.178478
#> 9            8 23.24792 55.50208 3.0671277 106.40778 0.9168529  8.267463
#> 10           9 24.53750 48.71250 3.0481545 108.47860 0.7083660  8.958716
#> 11          10 25.23750 46.14167 2.7362963 108.33039 0.7953714  9.839186
#> 12          11 25.99375 45.57500 2.5247955 114.11016 1.1639129  9.678549
#> 13          12 26.22292 46.08750 2.4093954  93.71706 1.7642328 14.626274
#> 14          13 26.58125 42.76042 2.1648261  88.46194 2.1201128 13.739670
#> 15          14 26.81250 40.07917 2.5717656  84.26684 2.5524181 12.701710
#> 16          15 26.53125 41.88333 2.6004247  81.27193 2.9331074  7.111067
#> 17          16 25.84375 45.85625 2.6373699  82.11262 3.2629044  4.965382
#> 18          17 24.30912 51.29309 2.8619390  83.59169 3.6441837  8.788306
#> 19          18 23.03667 55.56000 2.5690710  97.13183 3.6610023  7.458958
#> 20          19 21.31333 64.36833 2.0273140 101.31693 2.8916402  6.870040
#> 21          20 20.37667 71.48500 1.7145766  97.56517 2.4098856  9.107259
#> 22          21 20.11500 76.00000 1.4506764 108.74542 2.3846107 10.403598
#> 23          22 19.62833 80.31833 1.0338116 103.21117 2.5215777  7.981599
#> 24          23 19.50167 83.54833 0.8056148 115.57662 2.2451754  7.760536
#>       WS_sd    WD_sd
#> 1  1.688642 42.27307
#> 2  2.462471 45.21869
#> 3  2.052557 56.76272
#> 4  2.307165 61.24461
#> 5  2.612842 57.49787
#> 6  3.608765 79.88410
#> 7  3.970088 81.93771
#> 8  4.281308 76.18725
#> 9  4.461321 80.32155
#> 10 5.019880 82.40729
#> 11 5.163808 86.79045
#> 12 4.698675 77.97388
#> 13 4.860308 72.30656
#> 14 4.811506 72.50645
#> 15 4.239539 73.76020
#> 16 3.950678 79.40615
#> 17 3.638441 79.70563
#> 18 3.037288 77.50171
#> 19 2.273655 73.51274
#> 20 1.745916 72.43312
#> 21 1.680907 59.55001
#> 22 1.458446 65.59039
#> 23 1.389239 59.48205
#> 24 1.268269 44.96236