Skip to contents

Create a simple correlation table

Usage

tbl_corr(data, formula, digits = 3, caption = NULL, na_rm = FALSE)

Arguments

data

A data frame (or tibble).

formula

Two variables given in formula notation: var1~var2.

digits

The number if digits to round to. Defaults to 3.

caption

An override for the table caption. A sensible default is given.

na_rm

Should missing values be removed? Defaults to FALSE.

Value

An object of class flextable. If in an interactive session, the table will be viewable immediately.

Examples

# Not removing NAs is not recommended
tbl_corr(airquality, Ozone~Solar.R)
#> Missing values *not* automatically removed from calculation. 
#>  You may get NA values in your output.
#> This message is displayed once per session.
Correlation of Ozone vs. Solar.R

Ozone n

Ozone missing

Solar.R n

Solar.R missing

Observations Used

Correlation

153

37

153

7

153

NA

tbl_corr(airquality, Ozone~Solar.R, na_rm = TRUE)
Correlation of Ozone vs. Solar.R

Ozone n

Ozone missing

Solar.R n

Solar.R missing

Observations Used

Correlation

153

37

153

7

111

0.348