Description Usage Arguments Value Examples
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
1 | structure_df(data, max_string_length = 60, digits = 3)
|
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 |
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 |
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.