# 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')
Run the code above in your browser using DataLab