View source: R/weeklyfunction.R

weeklyfunction | R Documentation |

Generic function for obtaining 52 weekly values of a zoo object, by applying any R function to ALL the values in the object belonging to each one of the 52 calendar weeks (starting on Monday).

```
weeklyfunction(x, ...)
## Default S3 method:
weeklyfunction(x, FUN, na.rm=TRUE, na.rm.max=0, start="00:00:00",
start.fmt= "%H:%M:%S", tz, ...)
## S3 method for class 'zoo'
weeklyfunction(x, FUN, na.rm=TRUE, na.rm.max=0, start="00:00:00",
start.fmt= "%H:%M:%S", tz, ...)
## S3 method for class 'data.frame'
weeklyfunction(x, FUN, na.rm=TRUE, na.rm.max=0, start="00:00:00",
start.fmt= "%H:%M:%S", tz, dates=1, date.fmt="%Y-%m-%d",
out.type="data.frame", verbose=TRUE,...)
## S3 method for class 'matrix'
weeklyfunction(x, FUN, na.rm=TRUE, na.rm.max=0, start="00:00:00",
start.fmt= "%H:%M:%S", tz, dates=1, date.fmt="%Y-%m-%d",
out.type="data.frame", verbose=TRUE,...)
```

`x` |
zoo, xts, data.frame or matrix object, with daily or monthly time series. |

`FUN` |
Function that will be applied to ALL the values in |

`na.rm` |
Logical. Should missing values be removed? |

`na.rm.max` |
Numeric in [0, 1]. It is used to define the maximum percentage of missing values allowed in each month to keep the weekly aggregated value in the output object of this function. In other words, if the percentage of missing values in a given month is larger or equal than |

`start` |
character, indicating the starting time used for aggregating sub-daily time series into daily ones. It MUST be provided in the format specified by It is useful when the daily values start at a time different from |

`start.fmt` |
character indicating the format in which the time is provided in |

`tz` |
character, with the specification of the time zone used in both |

`dates` |
It is only used when |

`date.fmt` |
It is only used when |

`out.type` |
It is only used when |

`verbose` |
Logical; if TRUE, progress messages are printed |

`...` |
further arguments passed to or from other methods |

When `x`

is a zoo object, a numeric vector with 12 elements representing the computed monthly value for each month.

When `x`

is a data.frame which columns represent measurements at different gauging stations, the resulting object is a data.frame with 12 columns and as many rows as gauging stations are in `x`

, each row storing the computed 12 monthly value for each gauging station.

Due to the fact that `FUN`

is applied over all the elements in `x`

belonging to a given calendar month, its result will depend on the sampling frequency of `x`

and the type of function provided by `FUN`

(**special attention have to be put when FUN=sum**)

Mauricio Zambrano-Bigiarini, mzb.devel@gmail

`annualfunction`

, `seasonalfunction`

, `dm2seasonal`

, `daily2monthly`

, `daily2annual`

```
## Ex1: Computation of mean WEEKLY values from DAILY ts, removing any missing value in 'x'
# Loading DAILY streamflows (3 years) at the station
# Oca en Ona (Ebro River basin, Spain)
data(OcaEnOnaQts)
x <- OcaEnOnaQts
## Mean WEEKLY streamflows at station 'x'
weeklyfunction(x, FUN=mean, na.rm=TRUE)
######################
## Ex2: Computation of mean WEEKLY values from HOURLY ts, removing any missing value in 'x'
# Loading HOURLY streamflows for the station Karamea at Gorge
data(KarameaAtGorgeQts)
x <- KarameaAtGorgeQts
## Mean WEEKLY streamflows at station 'x'. Each day starts at 00:00:00
weeklyfunction(x, FUN=mean, na.rm=TRUE)
######################
## Ex3: Computation of mean WEEKLY values from HOURLY ts, removing any missing value in 'x'
## and starting each day at 08:00:00
# Loading HOURLY streamflows for the station Karamea at Gorge
data(KarameaAtGorgeQts)
x <- KarameaAtGorgeQts
## Mean WEEKLY streamflows at station 'x'. Each day starts at 00:00:00
weeklyfunction(x, FUN=mean, na.rm=TRUE, start="00:00:00")
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.