small updates, new function. now incl example

This commit is contained in:
agdamsbo 2019-11-25 12:05:24 +01:00
parent 7f032c7dad
commit 1ede313f99
6 changed files with 50 additions and 2 deletions

View File

@ -1,7 +1,7 @@
Package: daDoctoR
Type: Package
Title: FUNCTIONS FOR HEALTH RESEARCH
Version: 0.1.0.9035
Version: 0.1.0.9036
Author: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut")))
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
Description: I am a Danish medical doctor involved in neuropsychiatric research.

View File

@ -7,6 +7,7 @@ export(col_num)
export(comb_olr)
export(cpr_check)
export(cpr_sex)
export(cut_perc)
export(date_convert)
export(dob_extract_cpr)
export(euler_plot)

25
R/cut_perc.R Normal file
View File

@ -0,0 +1,25 @@
#' Creates factor by percentile from numeric vector.
#'
#' Cuts numeric vector in equal groups set by percentile.
#' Export is af factor with numeric labels.
#' @param vec name of vector
#' @param percentile percentile for cuts. No check is made, sholud be a divisor of 1 as .25 og .1. Standard is .1 for centiles.
#' @keywords percentile
#' @export
#' @examples
#' ##Tests the function by quantiles
#' cut_perc(sample(1:100, 50, replace=TRUE),.25)
cut_perc<-function (vec,percentile=.1)
{
p=percentile
v=as.numeric(vec)
perc <- factor(
findInterval(v, c(-Inf,
quantile(v, probs=seq(from=p,to=1-p,by=p), na.rm=TRUE), Inf)),
labels=c(1:(1/p)
))
return(perc)
}

View File

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/age_calc_function.R
% Please edit documentation in R/age_calc.R
\name{age_calc}
\alias{age_calc}
\title{Calculating age from date of birth}

22
man/cut_perc.Rd Normal file
View File

@ -0,0 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cut_perc.R
\name{cut_perc}
\alias{cut_perc}
\title{Creates factor by percentile from numeric vector.}
\usage{
cut_perc(vec, percentile = 0.1)
}
\arguments{
\item{vec}{name of vector}
\item{percentile}{percentile for cuts. No check is made, sholud be a divisor of 1 as .25 og .1. Standard is .1 for centiles.}
}
\description{
Cuts numeric vector in equal groups set by percentile.
Export is af factor with numeric labels.
}
\examples{
##Tests the function by quantiles
cut_perc(sample(1:100, 50, replace=TRUE),.25)
}
\keyword{percentile}