structure_df: data.frame structure summary in data.frame format

Description Usage Arguments Value Examples

View source: R/structure_df.R

Description

This function produces output very similar to the one obtained by the str function, only it returns a data.frame object which can be used for example in rmarkdown reports

Usage

1
structure_df(data, max_string_length = 60, digits = 3)

Arguments

data

A data.frame for which the structure is to be given

max_string_length

maximum string length in the sample_values column

digits

maximum number of digits shown for numeric variables

Value

A data.frame with the following columns:

variable

variable name

class

variable class

sample_values

sample of the values that variable can take for factor variables and main stasitics (mean, median etc) for a numeric variable

missing

percent missing values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(utilityFunctions)
sample_df <- data.frame(numeric_var = rnorm(1000),
                        factor_var = factor(sample(LETTERS, 1000, replace = TRUE)),
                        character_var = sample(letters, 1000, replace = TRUE),
                        logical_var = rnorm(1000) > 0,
                        date_var = seq.Date(as.Date("2020-01-01"),
                                            as.Date("2020-01-01") + 999,
                                            by = "day"),
                        stringsAsFactors = F)
sample_df$numeric_var[sample.int(nrow(sample_df), 150)] <- NA


# in the console one can just do:
str(sample_df)

# if we want to have something close to put in a report we can use:
structure_df(sample_df)

IyarLin/utilityFunctions documentation built on May 19, 2020, 12:50 p.m.