-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
113 lines (89 loc) · 3.37 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
output: github_document
editor_options:
markdown:
wrap: 72
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# wrappedtools <img src="wrappedtools_hex.png" align="right" height="139"/>
<!-- ![](wrappedtools_hex.png "wrappedtools hex"){width=20%} -->
<!-- badges: start -->
<!-- badges: end -->
The goal of 'wrappedtools' is to make my (and possibly your) life a bit
easier by a set of convenience functions for many common tasks like e.g.
computation of mean and SD and pasting them with ±. Instead of\
paste(round(mean(x),some_level), round(sd(x),some_level), sep='±')\
a simple meansd(x, roundDig = some_level) is enough.
## Installation
You can install the released version of 'wrappedtools' from CRAN or the
latest development version from github with:
``` r
devtools::install_github("abusjahn/wrappedtools")
```
```{r include=FALSE}
library(wrappedtools)
```
## Examples
This is a basic example which shows you how to solve a common problem,
that is, describe and test differences in some measures between 2
samples, rounding descriptive statistics to a reasonable precision in
the process:
```{r example1}
# Standard functions to obtain median and quartiles:
median(mtcars$mpg)
quantile(mtcars$mpg,probs = c(.25,.75))
# wrappedtools adds rounding and pasting:
median_quart(mtcars$mpg)
# on a higher level, this logic leads to
compare2numvars(data = mtcars, dep_vars = c('wt','mpg', "disp"),
indep_var = 'am',
gaussian = FALSE,
round_desc = 3)
```
To explain the **'wrapper'** part of the package name, here is another
example, using the ks.test as test for a Normal distribution, where
ksnormal simply wraps around the ks.test function:
```{r example2}
somedata <- rnorm(100)
ks.test(x = somedata, 'pnorm', mean=mean(somedata), sd=sd(somedata))
ksnormal(somedata)
```
Saving variable selections: Variables may fall into different groups:
Some are following a Gaussian distribution, others are ordinal or
factorial. There may be several grouping variables like treatment,
gender... To refer to such variables, it is convenient to have their
index and name stored. The name may be needed as character,
complex variable names like "size [cm]" may need to be surrounded by
backticks in some function calls but must not have those in others.
Function ColSeeker finds columns in tibbles or dataframes, based on name
pattern and/or class. This is comparable to the selection helpers in 'tidyselect',
but does not select the content of matching variables, but names,
positions, and count:
```{r example3}
gaussvars <- ColSeeker(data = mtcars,
namepattern = c('wt','mpg'))
gaussvars
#Exclusion based on pattern
factorvars <- ColSeeker(mtcars,
namepattern = c('a','cy'),
exclude = c('t'))
factorvars$names #drat excluded
ColSeeker(mtcars,varclass = 'numeric')$names
```
Workflow with ColSeeker and compare2numvars to describe and test a number of variables between 2 groups:
```{r example4}
compare2numvars(data = mtcars,
dep_vars=gaussvars$names,
indep_var = 'am',
gaussian = TRUE)
```
This should give you the general idea, I'll try to expand this intro
over time...