dems_neat | R Documentation |
Prints participant count, age mean and SD, and gender ratio, from given dataset.
dems_neat( data_per_subject, group_by = NULL, gender_col = NULL, age_col = NULL, male = "male", female = "female", percent = FALSE, round_perc = 0, show_fem = NULL, age_range = FALSE, age_min = NULL, age_max = NULL )
data_per_subject |
Data frame from which demographics are to be
calculated. Should contain columns named as " |
group_by |
Optionally the name(s) of column(s) from the data frame
provided as |
gender_col |
Optionally the name of column from the data frame that contains the gender (sex) information. |
age_col |
Optionally the name of column from the data frame that contains the age information. |
male |
Alternative code for male: by default, it is the string
|
female |
Alternative code for female: by default, it is the string
|
percent |
Logical. If |
round_perc |
Number |
show_fem |
Logical or |
age_range |
Logical, |
age_min |
If numeric given, removes all ages below (exclusive!) the given number before any age calculation.#' |
age_max |
If numeric given, removes all ages above (exclusive!) the given number before any age calculation. |
If gender_col
and/or age_col
are not specified, the
function will first look for columns named precisely "age
" and as
"gender
". If either is not found, the function looks for the same
names but with any lettercase (e.g. "AGE
" or "Gender
"). If
still no "gender
" column is found, the function looks for
"sex
" column in the same manner. If no column is found for either,
all related values will be counted as "unknown" (NA
).
If NA
values are found in either the age
or gender
column, the ratio (or count) of unknown cases will be displayed everywhere.
Otherwise it will simply not be displayed anywhere.
# below is an illustrative example dataset # (the "subject" and "measure_x" columns are not used in the function) dat = data.frame( subject = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), conditions = c('x', 'y', 'x', 'y', 'y', 'x', 'x', 'x', 'y', 'x'), gender = c(2, 2, 1, 2, 1, 2, 2, 2, 1, 1), age = c(6, 7, 8.5, 6, 5, 16.5, 17, 16, 45.8, 77), measure_x = c(83, 71, 111, 70, 92, 75, 110, 111, 110, 85), stringsAsFactors = TRUE ) # print demographics (age and gender) per "conditions": dems_neat(dat, group_by = 'conditions') # replace unlikely ages with NAs dems_neat(dat, group_by = 'conditions', age_min = 8, age_max = 50) # remove only high values, and display age ranges dems_neat(dat, group_by = 'conditions', age_max = 45, age_range = TRUE) # another dataset, with some missing values dat = data.frame( subject = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), conditions = c('x', 'y', 'x', 'y', 'y', 'x', 'x', 'x', 'y', 'x'), gender = c(2, 2, NA, NA, 1, 1, 1, 2, NA, NA), age = c(6, 7, 8.5, 6, 5, 16, NA, 16, 45, 77), measure_x = c(83, 71, 111, 70, 92, 75, 110, 111, 110, 85), stringsAsFactors = TRUE ) # again print demographics per "conditions": dems_neat(dat, group_by = 'conditions') # another dataset, with no "age"/"gender" columns dat = data.frame( subject = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), conditions = c('x', 'y', 'x', 'y', 'y', 'x', 'x', 'x', 'y', 'x'), geschlecht = c(2, 2, NA, NA, 1, 1, 1, 2, NA, NA), alter = c(6, 7, 8.5, 6, 5, 16, NA, 16, 45, 77), measure_y = c(83, 71, 111, 70, 92, 75, 110, 111, 110, 85), stringsAsFactors = TRUE ) # the following will return "unknowns" dems_neat(dat, group_by = 'conditions') # gender column specified dems_neat(dat, group_by = 'conditions', gender_col = 'geschlecht') # both columns specified dems_neat(dat, group_by = 'conditions', age_col = 'alter', gender_col = 'geschlecht')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.