diff --git a/DESCRIPTION b/DESCRIPTION index abd8509..5637dd8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: nottshcMethods Title: Helper functions for working with NHS healthcare data by the Data Science Team of the Nottinghamshire Healthcare NHS Foundation Trust -Version: 0.0.1 +Version: 0.1.0 Date: 2021-03-29 Authors@R: c( person("Milan", "Wiedemann", email = "milan.wiedemann@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-1991-282X")), diff --git a/NAMESPACE b/NAMESPACE index d432d64..54fb271 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,5 @@ # Generated by roxygen2: do not edit by hand export(hash) +export(sample_vector) export(theme_nottshc) diff --git a/R/sample_vector.R b/R/sample_vector.R new file mode 100644 index 0000000..4a0a405 --- /dev/null +++ b/R/sample_vector.R @@ -0,0 +1,21 @@ +#' CDU data science team ggplot2 theme +#' +#' A ggplot2 theme with a white panel background, no grid lines, +#' large axis and legend titles, +#' and increased text padding for better readability. +#' +#' @param values Vector- the thing you want to sample from +#' @param weights vector of integers the same length as values- the proportions +#' with which you want to sample +#' @param length integer- how long you want the return value to be- e.g. the +#' number of rows in a dataframe +#' +#' @export +sample_vector <- function(values, weights, length){ + + sample(values, length, replace = TRUE, prob = weights / sum(weights)) +} + +sample_vector(values = c(NA, "Male", "Female", "Other"), + weights = c(10, 50, 50, 2), + length = 100) diff --git a/man/sample_vector.Rd b/man/sample_vector.Rd new file mode 100644 index 0000000..1a89557 --- /dev/null +++ b/man/sample_vector.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sample_vector.R +\name{sample_vector} +\alias{sample_vector} +\title{CDU data science team ggplot2 theme} +\usage{ +sample_vector(values, weights, length) +} +\arguments{ +\item{values}{Vector- the thing you want to sample from} + +\item{weights}{vector of integers the same length as values- the proportions +with which you want to sample} + +\item{length}{integer- how long you want the return value to be- e.g. the +number of rows in a dataframe} +} +\description{ +A ggplot2 theme with a white panel background, no grid lines, +large axis and legend titles, +and increased text padding for better readability. +}