Learn R Programming

cursory

The goal of cursory is to make it easier to summarize data and look at your variables. It builds off dplyr and purrr. It is also compatible with dbplyr and remote data.

Installation

You can install the released version of cursory from CRAN with:

install.packages("cursory")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("halpo/cursory")

Example

This is a basic example which shows you how to solve a common problem:

library(dplyr)
library(cursory)
data(iris)

## basic summary statistics for each variable in a data frame.
cursory_all(group_by(iris, Species), lst(mean, median)) %>% ungroup() 
VariableSpeciesmeanmedian
Sepal.Lengthsetosa5.0065.00
Sepal.Lengthversicolor5.9365.90
Sepal.Lengthvirginica6.5886.50
Sepal.Widthsetosa3.4283.40
Sepal.Widthversicolor2.7702.80
Sepal.Widthvirginica2.9743.00
Petal.Lengthsetosa1.4621.50
Petal.Lengthversicolor4.2604.35
Petal.Lengthvirginica5.5525.55
Petal.Widthsetosa0.2460.20
Petal.Widthversicolor1.3261.30
Petal.Widthvirginica2.0262.00

## summary statistics for only numeric variables. 
cursory_if(iris, is.numeric, lst(Mean = mean, 'Std. Deviation' = sd))
VariableMeanStd. Deviation
Sepal.Length5.8433330.8280661
Sepal.Width3.0573330.4358663
Petal.Length3.7580001.7652982
Petal.Width1.1993330.7622377

## summary statistics for specific variables. 
cursory_at(iris, vars(ends_with("Length")), var)
Variablevar
Sepal.Length0.6856935
Petal.Length3.1162779

table_1

The cursory package also provides a table_1 function that allows for describing variables of a dataset for different subsets automatically. This is useful in creating the very common demographics “table 1”.

table_1(iris, Species)
VariableLevel(All)setosaversicolorvirginica
Sepal.LengthMin4.3004.3004.9004.900
Median5.8005.0005.9006.500
Mean5.8435.0065.9366.588
Max7.9005.8007.0007.900
SD0.8280.3520.5160.636
Sepal.WidthMin2.0002.3002.0002.200
Median3.0003.4002.8003.000
Mean3.0573.4282.7702.974
Max4.4004.4003.4003.800
SD0.4360.3790.3140.322
Petal.LengthMin1.0001.0003.0004.500
Median4.3001.5004.3005.500
Mean3.7581.4624.2605.552
Max6.9001.9005.1006.900
SD1.7650.1740.4700.552
Petal.WidthMin0.1000.1001.0001.400
Median1.3000.2001.3002.000
Mean1.1990.2461.3262.026
Max2.5000.6001.8002.500
SD0.7620.1050.1980.275

The table_1() function also tags the Variable column as a dontrepeat class column which make repeating values in columns not appear when formatted, so that tables are easier to read.

Copy Link

Version

Install

install.packages('cursory')

Monthly Downloads

9

Version

1.0.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Andrew Redd

Last Published

August 22nd, 2019

Functions in cursory (1.0.0)

table_1

Create a Dataset Summary Table (I.E. Table 1)
Npct

Combine count with a percent
add_class

Add to object helpers
ci

Confidence interval structure
cursory

Cursory Functions
dontrepeat

Indicate that when printing repeat values should be hidden.
percent

Designate a numeric vector as a percent.