R: It calculates the number of wet days for each month and each...
nwetdays
R Documentation
It calculates the number of wet days for each month and each year
Description
It calculates the number of wet days for each month and
each year
Usage
nwetdays(data, valmin = 0.5, origin = "1961-1-1", station = names(data))
Arguments
data
data frame R object containing daily
precipitation time series for several gauges (one gauge
time series per column).
valmin
threshold precipitation value [mm] for
wet/dry day indicator.
origin
character string "yyyy-mm-dd"
indicated the date of the first row of "data".
station
character string indicating the stations.
Default is names(data)
Value
Function returns a list of data frames containing the spell
length expressed in days
Examples
data(trentino)
year_min <- 1961
year_max <- 1990
period <- PRECIPITATION$year>=year_min & PRECIPITATION$year<=year_max
station <- names(PRECIPITATION)[!(names(PRECIPITATION) %in% c("day","month","year"))]
prec_mes <- PRECIPITATION[period,station]
## removing nonworking stations (e.g. time series with NA)
accepted <- array(TRUE,length(names(prec_mes)))
names(accepted) <- names(prec_mes)
for (it in names(prec_mes)) {
accepted[it] <- (length(which(!is.na(prec_mes[,it])))==length(prec_mes[,it]))
}
prec_mes <- prec_mes[,accepted]
## the dateset is reduced!!!
prec_mes <- prec_mes[,1:3]
origin <- paste(year_min,1,1,sep="-")
nwetdays <- nwetdays(prec_mes,origin)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(RGENERATEPREC)
Loading required package: copula
Loading required package: RGENERATE
Loading required package: RMAWGEN
Loading required package: chron
Loading required package: date
Loading required package: vars
Loading required package: MASS
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
Loading required package: urca
Loading required package: lmtest
Attaching package: 'vars'
The following object is masked from 'package:copula':
A
Loading required package: blockmatrix
Loading required package: Matrix
Loading required package: stringr
Attaching package: 'stringr'
The following object is masked from 'package:strucchange':
boundary
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/RGENERATEPREC/nwetdays.Rd_%03d_medium.png", width=480, height=480)
> ### Name: nwetdays
> ### Title: It calculates the number of wet days for each month and each
> ### year
> ### Aliases: nwetdays
>
> ### ** Examples
>
> data(trentino)
>
> year_min <- 1961
> year_max <- 1990
>
> period <- PRECIPITATION$year>=year_min & PRECIPITATION$year<=year_max
> station <- names(PRECIPITATION)[!(names(PRECIPITATION) %in% c("day","month","year"))]
> prec_mes <- PRECIPITATION[period,station]
>
> ## removing nonworking stations (e.g. time series with NA)
> accepted <- array(TRUE,length(names(prec_mes)))
> names(accepted) <- names(prec_mes)
> for (it in names(prec_mes)) {
+ accepted[it] <- (length(which(!is.na(prec_mes[,it])))==length(prec_mes[,it]))
+ }
>
> prec_mes <- prec_mes[,accepted]
> ## the dateset is reduced!!!
> prec_mes <- prec_mes[,1:3]
>
> origin <- paste(year_min,1,1,sep="-")
>
> nwetdays <- nwetdays(prec_mes,origin)
chr [1:3] "T0001" "T0014" "T0021"
'data.frame': 360 obs. of 5 variables:
$ month: num 0 0 0 0 0 0 0 0 0 0 ...
$ year : num 0 0 0 0 0 0 0 0 0 0 ...
$ T0001: num 0 0 0 0 0 0 0 0 0 0 ...
$ T0014: num 0 0 0 0 0 0 0 0 0 0 ...
$ T0021: num 0 0 0 0 0 0 0 0 0 0 ...
>
>
>
>
>
> dev.off()
null device
1
>