as.decimal: Simple and handy functions

View source: R/rtools.R

as.decimalR Documentation

Simple and handy functions

Description

attrcp(x,y) passes on attributes from x to y and returns the y with new attributes.

Usage

as.decimal(x = NULL)

Arguments

x

A data.frame or a coredata zoo object.

na.rm

If TRUE, remove NA's from data

type

'ma' for moving average (box-car), 'gauss' for Gaussian, 'binom' for binomial filter,' parzen' for Parzen filter, 'hanning' for Hanning filter, or 'welch' for Welch filter.

lowpass

True for smoothing, otherwise the highpass results is returned

triangle

a group of three stations with sea-level pressure', e.g. from ECA\&D.

nbins

number of bins/categories

Details

ensemblemean returns the ensemble mean for dsensemble objects. The argument FUN can also be used to estimate other statistics, e.g FUN='q95' where q95=function(x) apply(x,1,quantile,probs=0.95)

TGW uses triangulation of pressure measurements to estimate geostrophic wind based on Alexandersson et al. (1998), Glob. Atm. and Oce. Sys.

stand gives a standardised time series.

zeros counts the occurrence of zero values in a vector.

nv returns the number of valid points.

missval computes the percentage of missing data.

arec compares the number of record-breaking events to the number of events for a time series of iid data (sum(1/1:n))

strstrip strips off spaces before and after text in a string.

as.decimal converts between degree-minute-second into decimal value.

cv computes the coefficient of variation.

nv count the number of valid data points.

q5, q95, q975 and q995 are shortcuts to the 5%, 95%, 97.5% and 99.5% percentiles.

trend.coef and trend.pval return the coefficient and the p-value of the linear trend.

exit is a handy function for exiting the R session without saving.

figlab is a handy function for labelling figures (e.g. 'Figure 1')

ndig estimates the number of digits for round(x,ndig), e.g. in scales for plotting.

factor2numeric transforms a factor to a numeric object

rmse and RMSE calculate the root-mean-square error

leapyear checks if a year is a leap year

distance2ocean estimates the distance from a point to the ocean

lastyear checks the availability of data of a station object and returns the last year(s) of valid data entries

difftime.month returns the number of months between two dates

lastelementrecord checks last element of the record to see if they are the highest - a record

round2magnitude applied to a number, rounds up to the nearest order of magnitude

Value

as.decimal

Decimal value

trend.coef

Linear trend per decade

Author(s)

A. Mezghani

See Also

attrcp

Examples


## Monthly mean temperature at 'Oslo - Blindern' station 
data(Oslo)
## Compute the linear trend and the p-value on annual aggregated values 
tr <- trend.coef(coredata(annual(Oslo)))
pval <- trend.pval(coredata(annual(Oslo)))
## Not run: 
pp <- station(param='slp',cntr='Denmark',src='ecad')
wind <- TGW(subset(pp,is=c(1,3,10))
plot(wind)
ws <- sqrt(wind[,1]^2 + wind[,2]^2)
plot(ws)
hist(ws)

## Estimate wind for a larger group of stations
wind <- geostrophicwind(pp,nmax=10)
u <- subset(wind,param='u')
v <- subset(wind,param='u')
ws <- sqrt(u^2+v^2)
ws <- attrcp(v,ws)
class(ws) <- class(v)
attr(ws,'variable')='windspeed'
attr(ws,'longname')='geostrophic wind speed'
map(ws,FUN='quantile',probs=0.98)

## Test firstyears on HadCRUT4
if (!file.exists('~/Downloads/HadCRUT.4.6.0.0.median.nc')) {
  print('Download HadCRUT4')
  download.file('https://crudata.uea.ac.uk/cru/data/temperature/HadCRUT.4.6.0.0.median.nc',
                dest='~/Downloads/HadCRUT.4.6.0.0.median.nc') 
}

Obs <- annual(retrieve('~/Downloads/HadCRUT.4.6.0.0.median.nc',param='temperature_anomaly'))
lons <- rep(lon(Obs),length(lat(Obs)))
lats <- sort(rep(lat(Obs),length(lon(Obs))))
fy <- firstyear(Obs)
map(subset(Obs,it=1))
points(lons[fy==1850],lats[fy==1850])
map(Obs,FUN='firstyear')

## End(Not run)

## Check for leap years
leapyear(1999)
leapyear(2000)

## Calculate the distance to the ocean from the point 10E/60N 
distance2ocean(10, 60)


metno/esd documentation built on April 24, 2024, 9:19 p.m.