Week 5 Workbook
Loading required package: Matrix
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.3 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.2 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ ggplot2::%+%() masks psych::%+%()
✖ ggplot2::alpha() masks psych::alpha()
✖ dplyr::arrange() masks plyr::arrange()
✖ purrr::compact() masks plyr::compact()
✖ dplyr::count() masks plyr::count()
✖ dplyr::desc() masks plyr::desc()
✖ tidyr::expand() masks Matrix::expand()
✖ dplyr::failwith() masks plyr::failwith()
✖ dplyr::filter() masks stats::filter()
✖ dplyr::group_rows() masks kableExtra::group_rows()
✖ dplyr::id() masks plyr::id()
✖ dplyr::lag() masks stats::lag()
✖ dplyr::mutate() masks plyr::mutate()
✖ tidyr::pack() masks Matrix::pack()
✖ dplyr::rename() masks plyr::rename()
✖ dplyr::summarise() masks plyr::summarise()
✖ dplyr::summarize() masks plyr::summarize()
✖ tidyr::unpack() masks Matrix::unpack()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Week 5: Functions, Iteration, and purrr
Outline
- Questions on Homework
- Functions
purrr
- Problem Set and Question Time
Functions
- A
function
or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. - Functions typically take some input and return some specified output
Why Write Your Own Functions?
- Automate your workflow
- Prevent copy-paste errors (only need to update the function, not update the same task in a bunch of areas)
- Saves you time by providing tools that port to new projects
- Functions make you think, which improves the quality of our work
When Should You Write Your Own Functions?
- Hadley Wickham’s rule of thumb (which is common in a lot of CS and DS circles) is that if you have to copy-paste something more than twice, you should write a function
- But really you can write one whenever you’d like
- I often write functions when a link of code starts getting because it’s usually a good signal that I’m trying to do too much at once.
Types of Functions
- Vector functions take one or more vectors as input and return a vector as output.
- Data frame functions take a data frame as input and return a data frame as output.
- Plot functions that take a data frame as input and return a plot as output.
- and so on…
- We’ll talk extensively about this again when we talk about building figures and tables into your workflow in Week 8
Vector Functions
- In my work, I often want to POMP (Percentage Of Maximum Possible) score or z-score (standardize) variables, which allows me to get data on a standard and interpretable scale (percentage or standard deviations)
- I often want to do this with lots of variables, so to do each one separately would take forever and introduce chances for error.
Code
bfi %>%
select(matches("1$")) %>%
mutate(
E1 = (E1 - min(E1, na.rm = T))/(max(E1, na.rm = T) - min(E1, na.rm = T))*100
, A1 = (A1 - min(A1, na.rm = T))/(max(A1, na.rm = T) - min(A1, na.rm = T))*100
, C1 = (C1 - min(C1, na.rm = T))/(max(C1, na.rm = T) - min(C1, na.rm = T))*100
, N1 = (N1 - min(N1, na.rm = T))/(max(N1, na.rm = T) - min(N1, na.rm = T))*100
, O1 = (O1 - min(O1, na.rm = T))/(max(O1, na.rm = T) - min(O1, na.rm = T))*100
) %>%
head(10)
- Instead we could make this a function because I don’t want to talk about how long it took me to do that copy-pasting 😭
Code
- And remember, we could simplify this even more with
mutate_at()
! - And I know in this example it saved us about four lines of code, but having a function like this that you can just reference, especially in conjunction with
mutate_at()
saves you time in the short and long run.1
Writing Functions
- The first step in writing a function is to find the pattern:
- Let’s look back at the code above:
Code
E1 = (E1 - min(E1, na.rm = T))/(max(E1, na.rm = T) - min(E1, na.rm = T))*100
A1 = (A1 - min(A1, na.rm = T))/(max(A1, na.rm = T) - min(A1, na.rm = T))*100
C1 = (C1 - min(C1, na.rm = T))/(max(C1, na.rm = T) - min(C1, na.rm = T))*100
N1 = (N1 - min(N1, na.rm = T))/(max(N1, na.rm = T) - min(N1, na.rm = T))*100
O1 = (O1 - min(O1, na.rm = T))/(max(O1, na.rm = T) - min(O1, na.rm = T))*100
- Do you see the pattern?
We need three things to turn this into a function:
- A name. Here we’ll use rescale01 because this function rescales a vector to lie between 0 and 1.
- The arguments. The arguments are things that vary across calls and our analysis above tells us that we have just one. We’ll call it x because this is the conventional name for a numeric vector.
- The body. The body is the code that’s repeated across all the calls.
- The template of a function looks something like this:
- Although for local functions, I suggest something like this:
That’s not going to fit well on my slides, so I will minimally do it in class.
Following this, we return to our function:
Function Efficiency
- For most of our purposes, we may not care that much about how fast our code is
- Unless you’re working with huge data, things typically run fast
- But with a function like POMP, I may need to run it on 100+ variables each with 10,000+ observations, so speed may be a consideration
- So how do you speed up your functions?
- Avoid computing something twice
- Try to anticipate where things could go wrong
- So in our function, we calculate
min()
twice andmin()
once - We could just calculate
range()
instead, which reduces that computation time - Watch (note you have to run this in your console to see the difference)!
::::
- But those differences are really minimal right? Just -5^{-4} seconds.
- But across 150 variables that’s -0.0709 seconds.
Cautionary note on outputs
- The function we wrote above could be a “mutate()” function because the output is the same length / size as the input.
- If you write a function that drops cases, you will get an error because R can’t make the resulting vector fit back into the data frame
- Or, if you write a function that returns length
1
within mutate, it will just repeat that value for every row - So, just be careful to think about what the output is and make sure that it matches the use case you are working with!
More notes on outputs
- You can output anything you want from a function!
- data frames
- vectors
- single values
- strings
- lists (very common for base R and package functions!!)
- model objects
- plots
- tables
- etc.!
You Try:
Try turning the following into functions:
Code
mean(is.na(x))
mean(is.na(y))
mean(is.na(z))
x / sum(x, na.rm = TRUE)
y / sum(y, na.rm = TRUE)
z / sum(z, na.rm = TRUE)
round(x / sum(x, na.rm = TRUE) * 100, 1)
round(y / sum(y, na.rm = TRUE) * 100, 1)
round(z / sum(z, na.rm = TRUE) * 100, 1)
(x - mean(x, na.rm = T))/sd(x, na.rm = T)
(y - mean(y, na.rm = T))/sd(y, na.rm = T)
(z - mean(z, na.rm = T))/sd(z, na.rm = T)
Data Frame Functions
All the functions we’ve covered so far are vector functions (i.e. they input a vector, not a matrix or data frame and work well within
mutate()
calls)But if you have a long string of dplyr verbs, it can be useful to put these into a data frame function where you provide a data frame input and flexible way of naming the columns
I’m going to give a brief example here, but suggest that you check out more in R for Data Science.
Let’s start with a brief example. To do it, let’s first make the bfi data frame long
Code
- So maybe I want to get means for each of the Big Five from this, so I write a function like this:
- That didn’t work because we can’t specify grouping variables like that
- To get around it, we have to use something called embracing: We have to wrap the variables like this {{ trait }}
- This just nudges the dplyr functions to look inside the data frame for the column you specify
Code
tidy_describe <- function(df, var) {
df %>%
summarize(
mean = mean({{ var }}, na.rm = TRUE),
sd = sd({{ var }}, na.rm = TRUE),
median = median({{ var }}, na.rm = TRUE),
min = min({{ var }}, na.rm = TRUE),
max = max({{ var }}, na.rm = TRUE),
n = n(),
n_miss = sum(is.na({{ var }})),
.groups = "drop"
)
}
bfi_long %>%
group_by(trait) %>%
tidy_describe(value)
- Or remember when I had us getting counts and proportions for continuous x categorical relationships?
Wrap-Up
- This is just a brief introduction to functions.
- Functions are absolutely essential part of workflows, and you’ll see them pop up in every lesson from here on out (and you already saw them pop up in previous lessons)
- As we continue to see them, I’ll ramp up their complexity, showing you how to write functions for estimating models, model predictions, figures, tables, and more
Iteration and purrr
Iteration
Iteration is everywhere. It underpins much of mathematics and statistics. If you’ve ever seen the \(\Sigma\) symbol, then you’ve seen (and probably used) iteration.
Reasons for iteration:
- reading in multiple files from a directory
- running the same operation multiple times
- running different combinations of the same model
- creating similar figures / tables / outputs
for
loops
Enter for
loops. for
loops are the “OG” form of iteration in computer science. The basic syntax is below. Basically, we can use a for loop to loop through and print a series of things.
- The code above “loops” through 5 times, printing the iteration letter.
_apply()
family
- A somewhat faster version of
for
loops comes from the_apply()
family of functions, including:
[1] "a"
[1] "b"
[1] "c"
[1] "d"
[1] "e"
[[1]]
[1] "a"
[[2]]
[1] "b"
[[3]]
[1] "c"
[[4]]
[1] "d"
[[5]]
[1] "e"
[1] "a"
[1] "b"
[1] "c"
[1] "d"
[1] "e"
a b c d e
"a" "b" "c" "d" "e"
[1] "a"
[1] "b"
[1] "c"
[1] "d"
[1] "e"
a b c d e
"a" "b" "c" "d" "e"
purrr
and _map_()
functions
- Today, though, we’ll focus on the
map()
family of functions, which is the functions through whichpurrr
iterates.
[1] "a"
[1] "b"
[1] "c"
[1] "d"
[1] "e"
[[1]]
[1] "a"
[[2]]
[1] "b"
[[3]]
[1] "c"
[[4]]
[1] "d"
[[5]]
[1] "e"
- For a more thorough comparison of
for
loops, the_apply()
family, and_map_()
functions, see https://jennybc.github.io/purrr-tutorial/
purrr
and _map_()
predicates
- Today, though, we’ll focus on the
map()
family of functions, which is the functions through whichpurrr
iterates.
- Note that this returns a list, which we may not always want.
- With
purrr
, we can change the kind of output ofmap()
by adding a predicate, likelgl
,dbl
,chr
, anddf
. - So in the example above, we may have wanted just the characters to print. To do that we’d call
map_chr()
:
- Note that it also returns the concatenated character vector as well as printing each letter individually (i.e. iteratively).
purrr
and _map_()
antecedents
- How many mappings?
- Single mapping:
map_()
- Parallel (2) mapping(s):
map2_()
- 3 or more mappings:
pmap_()
- Single mapping:
- Note here that we can use
map2()
andpmap()
with the predicates from above.
List Columns and the Power of purrr
On the previous slide, we saw a data frame inside of a data frame. This is called a list column within a nested data frame.
In this case, we created a list column using map, but one of the best things about
purrr
is how it combines with thenest()
andunnest()
functions from thetidyr
package.We’ll return to
nest()
later to demonstrate how anything you would iterate across is also something we cannest()
by in long format data frames.
Use Cases
- Reading Data
- Cleaning Data
- Running Models
- (Plotting Figures - Week 8)
- (Creating Tables - Week 8)
Reading Data
There are a number of different cases where purrr
and map()
maybe useful for reading in data including:
- subject-level files for an experimental task
- subject- and task-level files for an experimental task
- EMA data
- longitudinal data
- web scraping and text mining
Reading Data: Participant-Level EMA
For this first example, I’ll show you how this would look with a for
loop before I show you how it looks with purrr
.
Assuming you have all the data in a single folder and the format is reasonably similar, you have the following basic syntax:
This works fine in this simple case, but where
purrr
really shines in when you need to make modifications to your data before combining, whether this be recoding, removing missing cases, or renaming variables.But first, the simple case of reading data. The code below will download a .zip file when you run it. Once, you do, navigate to your Desktop to unzip the folder. Open the R Project and you should be able to run the rest of the code
Code
Rows: 64 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 39 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 68 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 65 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 61 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 79 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 41 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 53 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 41 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 37 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 23 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 39 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 45 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 46 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 32 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 59 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 25 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 16 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 35 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 43 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 40 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 51 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 45 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 50 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 31 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 40 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 46 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 42 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 36 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 19 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 42 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 16 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 75 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 60 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 54 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 64 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 49 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 44 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 25 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 58 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
The code above creates a list of ID’s from the data path (files named for each person), reads the data in using the
map()
function frompurrr
, removes the “.csv” from the ID variable, then unnests the data, resulting in a data frame for each person.Now, we’re going to combine with what we learned about last time with codebooks.
Rows: 11 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (7): old_name, name, short_name, item_name, description, scale, reverse_...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
- Now, that we have a codebook, what are the next steps?
Code
Rows: 64 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 39 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 68 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 65 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 61 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 79 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 41 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 53 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 41 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 37 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 23 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 39 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 45 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 46 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 32 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 59 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 25 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 16 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 35 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 43 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 40 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 51 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 45 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 50 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 31 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 40 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 46 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 42 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 36 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 19 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 42 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 16 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 75 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 60 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 54 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 64 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 49 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 44 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 25 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 58 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
- pull old names in raw data from codebook
- pull new names from codebook
- select columns from codebook in loaded data
- rename columns with new names
Code
old.names <- codebook$old_name # pull old names in raw data from codebook
new.names <- codebook$item_name # pull new names from codebook
df1 <- tibble(
ID = list.files("data/example_1")
) %>%
mutate(data = map(ID, ~read_csv(sprintf("data/example_1/%s", .)))
, ID = str_remove_all(ID, ".csv")) %>%
unnest(data) %>%
select(ID, count, all_of(old.names)) %>% # select columns from codebook in loaded data
setNames(c("ID", "count", new.names)) # rename columns with new names
Rows: 64 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 39 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 68 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 65 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 61 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 79 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 41 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 53 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 41 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 37 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 23 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 39 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 45 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 46 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 32 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 59 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 25 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 16 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 35 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 43 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 40 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 51 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 45 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 50 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 31 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 40 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 46 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 42 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 36 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 19 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 42 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 16 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 75 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 60 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 54 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 48 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 64 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 49 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): E_Assert, N_Depr, N_EmoVol, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, E_En...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 55 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, A_Rspct, A_Cmpn, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 56 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 44 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 25 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, N_Depr, N_EmoVol, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 47 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, O_IntCur, C_Org, A_Rspct, C_Rspnbl, A_Cmpn, O...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 58 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (14): O_AesSens, E_Assert, N_Depr, N_EmoVol, O_IntCur, C_Org, C_Rspnbl, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Descriptives: Within-Person Correlations
With these kinds of data, the first thing, we may want to do is look at within-person correlations, which we can do with purrr
.
Code
We can access it like a list:
- But we can’t easily (well, nicely) just
unnest()
a matrix - We’ve lost a lot of information along the way
- So what do we do?
- Write a function, of course!
Code
- Let’s try unnesting again:
- There’s more I would usually do here to format a correlation table for each participant and output the file as a PDF or html so I can post it on GitHub / OSF
- But we’ll get there in Week 8/9!
Descriptives: Means, sds, etc.
Code
tidy_describe <- function(df) {
df %>%
pivot_longer(
-count
, names_to = "item"
, values_to = "value"
, values_drop_na = T
) %>%
group_by(item) %>%
summarize(
mean = mean(value, na.rm = TRUE),
sd = sd(value, na.rm = TRUE),
median = median(value, na.rm = TRUE),
min = min(value, na.rm = TRUE),
max = max(value, na.rm = TRUE),
n = n(),
n_miss = sum(is.na(value)),
.groups = "drop"
)
}
Models
We can put essentially anything into a nested data frame.
The magic happens because everything is indexed by the other columns in the data frame, so we can keep track of it
And unlike a normal list, we aren’t stuck with nested list structures that are really hard to parse and navigate through
Next, I’m going to show you how to use purrr with models
Modeling is not a focus of this class, but I want to demonstrate this as a workflow because it completely revolutionized mine!
But first, we need to format our data:
Code
To create composites, we’ll:
1. separate traits from items 2. group_by()
trait, count, and ID 3. calculate the composites using summarize()
Code
`summarise()` has grouped output by 'ID', 'count'. You can override using the
`.groups` argument.
Joining with `by = join_by(ID, count)`
Then we’ll get within-person centered values using our own little function!
Code
And grand-mean centered within-person averages
Code
And now we are ready to run our models. But first, we’ll nest()
our data.
And now run the models.
Code
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
And get data frames of the results:
Code
sprintfna <- function(x) ifelse(is.na(x), NA_character_, sprintf("%.2f", x))
tidy_tab <- function(m){
tidy(m, conf.int = T) %>%
mutate(pval = pnorm(abs(estimate/`std.error`), lower.tail = FALSE),
p = round(pval, digits = 3),
p = ifelse(pval < .001, "p < .001", paste0("p = ", p))) %>%
mutate_at(vars(estimate, conf.low, conf.high), sprintfna) %>%
mutate(CI = ifelse(is.na(conf.low), "", sprintf("[%s,%s]", conf.low, conf.high))) %>%
dplyr::select(term, estimate, CI, p)
}
nested_mods <- nested_mods %>%
mutate(tidy = map(model, tidy_tab))
nested_mods
Unnesting
Which we can print into pretty data frames
Unnesting & Tabling
Which we can pretty easily turn into tables:
Code
Code
hdr <- c(1, rep(3, 5))
names(hdr) <- c(" ", "Extraversion", "Agreeableness", "Conscientiousness", "Neuroticism", "Openness")
mod_tab <- mod_tab %>%
kable(.
, "html"
, escape = F
, col.names = c("Term", rep(c("<em>b</em>", "CI", "<em>p</em>"), times = 5))
, align = c("r", rep("c", 15))
, caption = "<strong>Table 1</strong><br><em>Multilevel Model Estimates of Between- and Within-Person Big Five-State Satisfaction Associations"
) %>%
kable_classic(full_width = F, html_font = "Times", font_size = 15) %>%
add_header_above(hdr)
mod_tab
Extraversion |
Agreeableness |
Conscientiousness |
Neuroticism |
Openness |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Term | b | CI | p | b | CI | p | b | CI | p | b | CI | p | b | CI | p |
(Intercept) | 2.98 | [2.93,3.03] | p < .001 | 2.98 | [2.93,3.03] | p < .001 | 2.97 | [2.92,3.02] | p < .001 | 2.99 | [2.94,3.03] | p < .001 | 2.97 | [2.93,3.02] | p < .001 |
value_c | -0.07 | [-0.14,0.00] | p = 0.029 | -0.02 | [-0.10,0.05] | p = 0.279 | 0.03 | [-0.05,0.10] | p = 0.231 | -0.01 | [-0.08,0.06] | p = 0.378 | 0.02 | [-0.05,0.09] | p = 0.29 |
value_gmc | 0.17 | [0.03,0.32] | p = 0.008 | 0.13 | [-0.05,0.31] | p = 0.081 | 0.19 | [0.06,0.32] | p = 0.003 | -0.09 | [-0.19,0.01] | p = 0.032 | 0.14 | [-0.04,0.33] | p = 0.067 |
value_c:value_gmc | 0.02 | [-0.17,0.22] | p = 0.399 | 0.16 | [-0.12,0.44] | p = 0.127 | 0.15 | [-0.04,0.34] | p = 0.061 | -0.19 | [-0.34,-0.03] | p = 0.009 | 0.25 | [0.01,0.49] | p = 0.019 |
sd__(Intercept) | 0.00 | 0.04 | 0.00 | 0.00 | 0.03 | ||||||||||
sd__Observation | 1.16 | 1.15 | 1.17 | 1.15 | 1.16 |
Appendix
Appendix: Sourcing Functions
Footnotes
Fun fact. I wrote this example and used POMP scores because I like to make them my personality and then noticed it’s the same example used by R4DS↩︎