-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 274225e
Showing
9 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Package: birk | ||
Type: Package | ||
Title: MA Birk functions | ||
Version: 1.0 | ||
Date: 2014-06-25 | ||
Author: Matthew A Birk | ||
Maintainer: Matthew A Birk <matthewabirk@gmail.com> | ||
Description: This is a compilation of my functions that I found useful to make. It currently includes a standard error function that behaves identically to sd() and a unit of measurement conversion function. | ||
License: GPL-2 | ||
Packaged: 2014-06-25 15:06:18 UTC; matthewbirk | ||
NeedsCompilation: no | ||
Repository: CRAN | ||
Date/Publication: 2014-06-26 00:21:17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
0e19565b231fcd1376e12bb59a93e600 *DESCRIPTION | ||
8b54e5a89fbda3af5e077053d40bec76 *NAMESPACE | ||
caf6df09f162a79c30e030d5e95b8486 *R/conv_unit.R | ||
e1be48e649ec90a21ab3762f9ad49d88 *R/se.R | ||
f9be04200313474c24bce672bb043d73 *man/birk-package.Rd | ||
5cd83527090fa7d5348a3d050e1d34a2 *man/conv_unit.Rd | ||
83af6a528ae2f49598d6b71f9171c048 *man/conv_unit_options.Rd | ||
da8606d7fa4c8392fde1d94e2188219f *man/se.Rd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exportPattern("^[[:alpha:]]+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Created by Matthew A. Birk | ||
|
||
# Converts common units for a variety of dimensions | ||
|
||
conv_unit_options=list( | ||
Area=c('nm2','um2','mm2','cm2','m2','hectacre','km2','in2','ft2','yd2','acre','mi2','naut_mi2'), | ||
Duration=c('nsec','usec','msec','sec','min','hr','day','wk','mon','yr','dec','cen','mil'), | ||
Length=c('nm','um','mm','cm','m','km','inch','ft','yd','mi','naut_mi','light_yr'), | ||
Mass=c('ug','mg','g','kg','metric_ton','oz','lb','short_ton','long_ton','stone'), | ||
Pressure=c('atm','Pa','hPa','kPa','torr','mmHg','inHg','mbar','bar','dbar','psi'), | ||
Speed=c('mm_per_sec','cm_per_sec','m_per_sec','km_per_sec','ft_per_sec','kph','mph','knot'), | ||
# Temperature=c('C','F','K'), | ||
Volume=c('ml','l','m3','us_tsp','us_tbsp','us_oz','us_cup','us_pint','us_quart','us_gal','in3','ft3','imp_tsp','imp_tbsp','imp_oz','imp_pint','imp_quart','imp_gal') | ||
) | ||
.conversions=data.frame() | ||
.conversions=rbind(.conversions,data.frame(dim=rep('area',times=length(conv_unit_options[['Area']])),unit=c('nm2','um2','mm2','cm2','m2','hectacre','km2','in2','ft2','yd2','acre','mi2','naut_mi2'),std=c(1e18,1e12,1e6,1e4,1,1e-4,1e-6,(100/2.54)^2,(100/2.54/12)^2,(100/2.54/36)^2,(100/2.54/12)^2/43560,(100/2.54/12)^2/43560/640,1/3429904))) | ||
.conversions=rbind(.conversions,data.frame(dim=rep('duration',times=length(conv_unit_options[['Duration']])),unit=c('nsec','usec','msec','sec','min','hr','day','wk','mon','yr','dec','cen','mil'),std=c(1e9,1e6,1e3,1,1/60,1/3600,1/86400,1/604800,1/(86400*365.25/12),1/(86400*365.25),1/(86400*3652.5),1/(86400*36525),1/(86400*365250)))) | ||
.conversions=rbind(.conversions,data.frame(dim=rep('length',times=length(conv_unit_options[['Length']])),unit=c('nm','um','mm','cm','m','km','inch','ft','yd','mi','naut_mi','light_yr'),std=c(1e9,1e6,1e3,100,1,1e-3,100/2.54,100/2.54/12,100/2.54/36,100/2.54/12/5280,1/1852,1/9460730472580800))) | ||
.conversions=rbind(.conversions,data.frame(dim=rep('mass',times=length(conv_unit_options[['Mass']])),unit=c('ug','mg','g','kg','metric_ton','oz','lb','short_ton','long_ton','stone'),std=c(1e6,1e3,1,0.001,1e-6,1/28.349523125,2.20462234e-3,1/907184.74,1/1.016e6,2.20462234e-3/14))) | ||
.conversions=rbind(.conversions,data.frame(dim=rep('pressure',times=length(conv_unit_options[['Pressure']])),unit=c('atm','Pa','hPa','kPa','torr','mmHg','inHg','mbar','bar','dbar','psi'),std=c(1,101325,1013.25,101.325,760,760,1/(3386.389/101325),1013.25,1.01325,10.1325,14.69594877551))) | ||
.conversions=rbind(.conversions,data.frame(dim=rep('speed',times=length(conv_unit_options[['Speed']])),unit=c('mm_per_sec','cm_per_sec','m_per_sec','km_per_sec','ft_per_sec','kph','mph','knot'),std=c(1e3,100,1,1e-3,100/2.54/12,1e-3*3600,100/2.54/12/5280*3600,1/1852*3600))) | ||
#.conversions=rbind(.conversions,data.frame(dim=rep('temperature',times=length(conv_unit_options[['Temperature']])),unit=c('C','F','K'),std=c(1,expression(9/5+32/value),expression(273.15/value+1)))) | ||
.conversions=rbind(.conversions,data.frame(dim=rep('volume',times=length(conv_unit_options[['Volume']])),unit=c('ml','l','m3','us_tsp','us_tbsp','us_oz','us_cup','us_pint','us_quart','us_gal','in3','ft3','imp_tsp','imp_tbsp','imp_oz','imp_pint','imp_quart','imp_gal'),std=c(1e3,1,1e-3,1/3.785411784*768,1/3.785411784*256,1/3.785411784*128,1/3.785411784*16,1/3.785411784*8,1/3.785411784*4,1/3.785411784,61.0237440947323,61.0237440947323/1728,1/4.54609*768,1/4.54609*256,1/4.54609*160,1/4.54609*8,1/4.54609*4,1/4.54609))) | ||
|
||
conv_unit=function(x,from,to) | ||
{ | ||
unit=std=NULL | ||
from=as.character(substitute(from)) | ||
to=as.character(substitute(to)) | ||
if(nrow(subset(.conversions,unit==from,dim))==0) stop('the from argument is not an acceptable unit') | ||
if(nrow(subset(.conversions,unit==to,dim))==0) stop('the to argument is not an acceptable unit') | ||
if(subset(.conversions,unit==from,dim)!=subset(.conversions,unit==to,dim)) stop('these units cannot be converted because they are of different dimensions') | ||
value=x/subset(.conversions,unit==from,std,drop=T) | ||
return(value*subset(.conversions,unit==to,std,drop=T)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Created by Matthew A. Birk | ||
|
||
# Calculates the standard error of a vector | ||
|
||
se=function(x,na.rm=FALSE) | ||
{ | ||
return(sqrt(var(if (is.vector(x)) x else as.double(x),na.rm=na.rm)/length(x))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
\name{birk-package} | ||
\alias{birk-package} | ||
\alias{birk} | ||
\docType{package} | ||
\title{MA Birk functions} | ||
\description{This is a compilation of my functions that I found useful to make. It currently includes a standard error function that behaves identically to sd() and a unit of measurement conversion function.} | ||
\details{ | ||
\tabular{ll}{ | ||
Package: \tab birk\cr | ||
Type: \tab Package\cr | ||
Version: \tab 1.0\cr | ||
Date: \tab 2014-06-25\cr | ||
License: \tab GPL-2\cr | ||
} | ||
} | ||
\author{ | ||
Matthew A Birk | ||
|
||
Maintainer: Matthew A Birk <matthewabirk@gmail.com> | ||
} | ||
\keyword{ package } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
\name{conv_unit} | ||
\alias{conv_unit} | ||
\title{Convert Units of Measurement} | ||
\description{This function converts common units of measurement for a variety of dimensions. See conv_unit_options for all options.} | ||
\usage{conv_unit(x, from, to)} | ||
\arguments{ | ||
\item{x}{the measurement value in original units.} | ||
\item{from}{the unit in which the measurement was made} | ||
\item{to}{the unit to which the measurment is to be converted} | ||
} | ||
\details{The conversion values have been defined based primarily from international weight and measurement authorities (e.g. General Conference on Weights and Measures, International Committee for Weights and Measures, etc.). While much effort was made to make conversions as accurate as possible, you should check the accuracy of conversions to ensure that conversions are precise enough for your applications.} | ||
\author{Matthew A. Birk} | ||
\note{All non-metric units of mass are based on the avoirdupois system.} | ||
\seealso{ | ||
\code{\link{conv_unit_options}} | ||
} | ||
\examples{ | ||
conv_unit(2.54, cm, inch) # Result = 1 inch | ||
conv_unit(seq(1, 10), kg, short_ton) # A vector of measurement values can be converted | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
\name{conv_unit_options} | ||
\alias{conv_unit_options} | ||
\docType{data} | ||
\title{Unit of Measurement Conversion Options} | ||
\description{This dataset shows what units of measurement can be converted with the function conv_unit.} | ||
\usage{conv_unit_options} | ||
\details{All non-metric units of mass are based on the avoirdupois system.} | ||
\source{The conversion values have been defined based primarily from international weight and measurement authorities (e.g. General Conference on Weights and Measures, International Committee for Weights and Measures, etc.). While much effort was made to make conversions as accurate as possible, you should check the accuracy of conversions to ensure that conversions are precise enough for your applications.} | ||
\seealso{ | ||
\code{\link{conv_unit}} | ||
} | ||
\examples{ | ||
conv_unit_options | ||
conv_unit_options['Pressure'] | ||
} | ||
\keyword{datasets} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
\name{se} | ||
\alias{se} | ||
\title{Standard Error} | ||
\description{This function computes the standard error of the values in x. If na.rm is TRUE then missing values are removed before computation proceeds.} | ||
\usage{se(x, na.rm = FALSE)} | ||
\arguments{ | ||
\item{x}{a numeric vector or an R object which is coercible to one by as.vector(x, "numeric").} | ||
\item{na.rm}{logical. Should missing values be removed?} | ||
} | ||
\author{Matthew A. Birk} | ||
\seealso{ | ||
\code{\link{sd}},\code{\link{var}} | ||
} | ||
\examples{ | ||
se(1:10) | ||
} |