Edit the code chunks below and knit the document. You can pipe your objects to glimpse() or print() to display them.

NOTE: There are many code chunks with errors in the .Rmd file, paired with code chunks in which you are supposed to fix the error. Once you have fixed the errors, you are welcome to delete the error code chunk to reduce clutter and facilitate knitting.

Useful shortcuts

Ctrl + Shift + M will insert a pipe. By default, it produces %>%, but if you want it to produce |> this is an option in Global Options –> Code –> “Use Native Pipe Operator”.

Ctrl + Enter will run an entire code chunk if your cursor is anywhere inside that code chunk (no need to highlight the code).

Tidy data

The following data table is not tidy. Use tibble() or tribble()to manually create the tidy version of this table.

NOTE: In this problem, you will still have the same number of rows as before.

# do not edit this chunk
untidy <- tribble(
  ~id, ~stats, ~p.value, ~conf.int,
  "A", "t(26) = -0.424", 0.6749,  "[-0.444, 0.292]",
  "B", "t(19) =  0.754", 0.4600,  "[-0.287, 0.610]",
  "C", "t(19) =  4.289", 0.0004,  "[ 0.374, 1.088]"
) |> print()
## # A tibble: 3 × 4
##   id    stats          p.value conf.int       
##   <chr> <chr>            <dbl> <chr>          
## 1 A     t(26) = -0.424  0.675  [-0.444, 0.292]
## 2 B     t(19) =  0.754  0.46   [-0.287, 0.610]
## 3 C     t(19) =  4.289  0.0004 [ 0.374, 1.088]
# your version can have different column names in a different order
tidy <- tibble(
  id = c("A", "B", "C"),
  df = c(26, 19, 19),
  t_value = c(-0.424, 0.754, 4.289),
  p_value = c(0.6749, 0.4600, 0.0004),
  conf_low = c(-0.444, -0.287, 0.374),
  conf_high = c(0.292, 0.610, 1.088)
)

print(tidy)
## # A tibble: 3 × 6
##   id       df t_value p_value conf_low conf_high
##   <chr> <dbl>   <dbl>   <dbl>    <dbl>     <dbl>
## 1 A        26  -0.424  0.675    -0.444     0.292
## 2 B        19   0.754  0.46     -0.287     0.61 
## 3 C        19   4.29   0.0004    0.374     1.09

Pivot functions

The questions in this section (other than loading the data) all have errors. Fix the errors.

Load data

Load the dataset reprores::sensation_seeking as ss.

library(readr)

ss <- read_csv("~/Desktop/ss.csv")

glimpse(ss)
## Rows: 27,021
## Columns: 17
## $ id      <dbl> 3144, 133, 175, 285, 1, 3, 4, 5, 6, 7, 8, 9, 10, 12, 11, 13, 1…
## $ user_id <dbl> 0, 1, 2, 5, 8, 9, 10, 17, 19, 20, 21, 22, 23, 24, 27, 30, 31, …
## $ date    <date> 2006-05-07, 2004-12-08, 2005-01-14, 2005-02-22, 2004-09-29, 2…
## $ sss1    <dbl> 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0,…
## $ sss2    <dbl> 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1,…
## $ sss3    <dbl> 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0,…
## $ sss4    <dbl> 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0,…
## $ sss5    <dbl> 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0,…
## $ sss6    <dbl> 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0,…
## $ sss7    <dbl> 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0,…
## $ sss8    <dbl> 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,…
## $ sss9    <dbl> 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1,…
## $ sss10   <dbl> 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,…
## $ sss11   <dbl> 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1,…
## $ sss12   <dbl> 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1,…
## $ sss13   <dbl> 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0,…
## $ sss14   <dbl> 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,…

pivot_longer

Convert from wide to long format.

# has an error
ss_long <- ss |>
  pivot_longer(names_to = "question", 
               values_to = "score") |>
  glimpse()
## Error in `pivot_longer()`:
## ! `cols` must select at least one column.
# corrects the error
ss_long <- ss |>
  pivot_longer(
    cols = -c(user_id, date),
    names_to = "question",
    values_to = "score"
  )

glimpse(ss_long)
## Rows: 405,315
## Columns: 4
## $ user_id  <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1…
## $ date     <date> 2006-05-07, 2006-05-07, 2006-05-07, 2006-05-07, 2006-05-07, …
## $ question <chr> "id", "sss1", "sss2", "sss3", "sss4", "sss5", "sss6", "sss7",…
## $ score    <dbl> 3144, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 133, 0, 1, 1,…

pivot_wider

Convert back to wide format. Make sure ss_wide is the same as ss.

# has an error
ss_wide <- ss_long |>
  pivot_wider(question, score) |>
  glimpse()
## Error in `pivot_wider()`:
## ! Can't select columns that don't exist.
## ✖ Column `name` doesn't exist.
# corrects the error
ss_wide <- pivot_wider(
  ss_long,
  names_from = question,
  values_from = score
)

glimpse(ss_wide)
## Rows: 27,021
## Columns: 17
## $ user_id <dbl> 0, 1, 2, 5, 8, 9, 10, 17, 19, 20, 21, 22, 23, 24, 27, 30, 31, …
## $ date    <date> 2006-05-07, 2004-12-08, 2005-01-14, 2005-02-22, 2004-09-29, 2…
## $ id      <dbl> 3144, 133, 175, 285, 1, 3, 4, 5, 6, 7, 8, 9, 10, 12, 11, 13, 1…
## $ sss1    <dbl> 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0,…
## $ sss2    <dbl> 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1,…
## $ sss3    <dbl> 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0,…
## $ sss4    <dbl> 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0,…
## $ sss5    <dbl> 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0,…
## $ sss6    <dbl> 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0,…
## $ sss7    <dbl> 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0,…
## $ sss8    <dbl> 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,…
## $ sss9    <dbl> 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1,…
## $ sss10   <dbl> 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,…
## $ sss11   <dbl> 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1,…
## $ sss12   <dbl> 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1,…
## $ sss13   <dbl> 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0,…
## $ sss14   <dbl> 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,…

Tidy verbs

The questions in this section all have errors. Fix the errors.

separate

Split the question column from ss_long into two columns: domain and qnumber.

# has an error
ss_sep <- ss_long |>
  separate(question, domain, qnumber, sep = 3) |>
  glimpse()
## Error:
## ! object 'qnumber' not found
# corrects the error
ss_sep <- ss_long |>
  separate(
    col = question,
    into = c("domain", "qnumber"),
    sep = "(?=[0-9])"
  )
## Warning: Expected 2 pieces. Additional pieces discarded in 135105 rows [11, 12, 13, 14,
## 15, 26, 27, 28, 29, 30, 41, 42, 43, 44, 45, 56, 57, 58, 59, 60, ...].
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 27021 rows [1, 16, 31,
## 46, 61, 76, 91, 106, 121, 136, 151, 166, 181, 196, 211, 226, 241, 256, 271,
## 286, ...].
glimpse(ss_sep)
## Rows: 405,315
## Columns: 5
## $ user_id <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,…
## $ date    <date> 2006-05-07, 2006-05-07, 2006-05-07, 2006-05-07, 2006-05-07, 2…
## $ domain  <chr> "id", "sss", "sss", "sss", "sss", "sss", "sss", "sss", "sss", …
## $ qnumber <chr> NA, "1", "2", "3", "4", "5", "6", "7", "8", "9", "1", "1", "1"…
## $ score   <dbl> 3144, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 133, 0, 1, 1, …

unite

Put the id and user_id columns together into a new column named super_id. Make it in a format like “id-user_id”.

# has an error
ss_unite <- ss_sep |>
  unite(id, user_id, "super_id", sep = "-") |>
  glimpse()
## Error in `unite()`:
## ! Can't select columns that don't exist.
## ✖ Column `super_id` doesn't exist.
# corrects the error
ss_unite <- ss_sep |>
  unite(
    super_id,
    domain,
    user_id,
    sep = "-"
  )

glimpse(ss_unite)
## Rows: 405,315
## Columns: 4
## $ super_id <chr> "id-0", "sss-0", "sss-0", "sss-0", "sss-0", "sss-0", "sss-0",…
## $ date     <date> 2006-05-07, 2006-05-07, 2006-05-07, 2006-05-07, 2006-05-07, …
## $ qnumber  <chr> NA, "1", "2", "3", "4", "5", "6", "7", "8", "9", "1", "1", "1…
## $ score    <dbl> 3144, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 133, 0, 1, 1,…

pivot_longer (AGAIN!)

The following code takes the wide data you create before and tries to complete the two steps (pivot_longer() and separate()) above in a single step.

# has an error
ss_long2 <- ss_wide |>
  #changes column names (DO NOT EDIT THIS)
  set_names(c("id", "user_id", "date", 
              "sss:1", "sss:2", "sss:3", "sss:4", "sss:5", "sss:6",
              "sss:7", "sss:8", "sss:9", "sss:10", "sss:11", "sss:12",
              "sss:13", "sss:14")) |>
  #(EDIT THIS BELOW)
  pivot_longer(cols = sss:1:sss:14,
               names_to = matrix("domain", "qnumber"),
               names_sep = NA,
               values_to = "score") |>
  glimpse()
## Error in `matrix()`:
## ! non-numeric matrix extent
# corrects the error
ss_long2 <- ss_wide |>
  set_names(c("id", "user_id", "date",
              "sss:1", "sss:2", "sss:3", "sss:4", "sss:5", "sss:6",
              "sss:7", "sss:8", "sss:9", "sss:10", "sss:11", "sss:12",
              "sss:13", "sss:14")) |>
  pivot_longer(
    cols = starts_with("sss:"),
    names_to = c("domain", "qnumber"),
    names_sep = ":",
    values_to = "score"
  )

glimpse(ss_long2)
## Rows: 378,294
## Columns: 6
## $ id      <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,…
## $ user_id <date> 2006-05-07, 2006-05-07, 2006-05-07, 2006-05-07, 2006-05-07, 2…
## $ date    <dbl> 3144, 3144, 3144, 3144, 3144, 3144, 3144, 3144, 3144, 3144, 31…
## $ domain  <chr> "sss", "sss", "sss", "sss", "sss", "sss", "sss", "sss", "sss",…
## $ qnumber <chr> "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",…
## $ score   <dbl> 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1,…

Pipes

Connect with pipes

Re-write the following sequence of commands into a single ‘pipeline’.

# do not edit this chunk
x <- 1:20      # integers from 1:20
y <- rep(x, 2) # then repeat them twice
z <- sum(y)    # and then take the sum
z
## [1] 420
z <- (1:20) |>
  rep(2) |>
  sum()

z
## [1] 420

Deconnect pipes

Deconstruct the pipeline below back into separate commands.

# do not edit this chunk
lager <- LETTERS[c(18, 5, 7, 1, 12)] |>
  rev() |>
  paste(collapse = "") |>
  print()
## [1] "LAGER"
lager <- LETTERS[c(18, 5, 7, 1, 12)]

lager <- rev(lager)

lager <- paste(lager, collapse = "")

print(lager)
## [1] "LAGER"

Pivot vs tidy verbs

Load the dataset reprores::family_composition.

family_comp <- read_csv(
  "https://psyteachr.github.io/reprores-v3/data/family_composition.csv"
)

glimpse(family_comp)
## Rows: 19,169
## Columns: 11
## $ user_id  <dbl> 8, 67, 98, 103, 164, 233, 235, 253, 256, 271, 298, 332, 426, …
## $ sex      <chr> "male", "female", "female", "female", "female", "female", "ma…
## $ age      <dbl> 38.1, 19.7, 19.4, 20.6, 20.3, 19.3, 18.7, 19.5, 19.7, 24.5, 1…
## $ momage   <dbl> 25, 29, NA, NA, 24, NA, NA, 24, NA, 21, 28, NA, NA, NA, NA, N…
## $ dadage   <dbl> 27, 31, NA, NA, NA, NA, NA, 25, NA, 22, NA, NA, NA, NA, NA, N…
## $ oldbro   <dbl> 0, 1, 1, 2, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 2, 0, 1, 0, 0, 0…
## $ oldsis   <dbl> 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 2, 0, 0…
## $ youngbro <dbl> 0, 0, 0, 0, 0, 0, 1, 1, 0, 2, 1, 0, 2, 0, 0, 2, 0, 1, 1, 1, 2…
## $ youngsis <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0…
## $ twinbro  <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ twinsis  <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…

The columns oldbro through twinsis give the number of siblings of that age and sex. Put this into long format and create separate columns for sibling age (sibage = old, young, twin) and sex (sibgender = bro, sis).

(As an aside, it is unclear to me what the correspondence between the “bro/sis” responses, which are more gendered labels, and the biological sex variable is (is this response about sex or gender?), hmm)

Use pivot functions

family_pivot <- family_comp |>
  pivot_longer(
    cols = oldbro:twinsis,
    names_to = c("sibage", "sibgender"),
    names_pattern = "(old|young|twin)(bro|sis)",
    values_to = "n_siblings"
  )

glimpse(family_pivot)
## Rows: 115,014
## Columns: 8
## $ user_id    <dbl> 8, 8, 8, 8, 8, 8, 67, 67, 67, 67, 67, 67, 98, 98, 98, 98, 9…
## $ sex        <chr> "male", "male", "male", "male", "male", "male", "female", "…
## $ age        <dbl> 38.1, 38.1, 38.1, 38.1, 38.1, 38.1, 19.7, 19.7, 19.7, 19.7,…
## $ momage     <dbl> 25, 25, 25, 25, 25, 25, 29, 29, 29, 29, 29, 29, NA, NA, NA,…
## $ dadage     <dbl> 27, 27, 27, 27, 27, 27, 31, 31, 31, 31, 31, 31, NA, NA, NA,…
## $ sibage     <chr> "old", "old", "young", "young", "twin", "twin", "old", "old…
## $ sibgender  <chr> "bro", "sis", "bro", "sis", "bro", "sis", "bro", "sis", "br…
## $ n_siblings <dbl> 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0,…

Extra Problem: Multiple steps

Tidy the data from reprores::eye_descriptions. This dataset contains descriptions of the eyes of 50 people by 220 raters (user_id). Some raters wrote more than one description per face (maximum 4), separated by commas, semicolons, or slashes.

eye_data <- read_csv(
  "https://psyteachr.github.io/reprores-v3/data/eye_descriptions.csv"
)

glimpse(eye_data)
## Rows: 220
## Columns: 53
## $ user_id <dbl> 508844, 508966, 508976, 509196, 509286, 509400, 509503, 509665…
## $ sex     <chr> "male", "female", "female", "female", "female", "male", "femal…
## $ age     <dbl> 19.0, 20.4, 24.8, 14.6, 16.7, NA, 36.2, 20.7, 5.0, 18.2, 17.4,…
## $ t1      <chr> "empty", "bored", "Dark high on drugs", "soft brown", "brown",…
## $ t2      <chr> "light", "cafinated", "Brown bug eyed", "green, brown", "big",…
## $ t3      <chr> "cheery", "nice", "Greenish brown bangs", "green", "oval", "gr…
## $ t4      <chr> "sad", "off kilter", "Dark look diff directions", "hurt", "bro…
## $ t5      <chr> "focused", "bitchy", "Mexican eyes alret", "Rich Brown", "brow…
## $ t6      <chr> "creative", "average", "Gray sketch", "grey blue", "blue", "cr…
## $ t7      <chr> "lost", "slightly dejected", "Too far brown", "soft", "brown,d…
## $ t8      <chr> "too open", "surprised", "Gray old suspicious", "shiny", "blue…
## $ t9      <chr> "not interesting", "kinda pretty", "Dark fake lashes", "Brown,…
## $ t10     <chr> "hiding something", "engaged", "Blue pretty older", "Blue", "b…
## $ t11     <chr> "closed", "tired frayed sweet", "Mexican dark common", "perfec…
## $ t12     <chr> "depressing", "sad", "Brown dead blank", "blue, grey, tan", "b…
## $ t13     <chr> "confused", "average", "Dark big blank", "amazing", "brown", "…
## $ t14     <chr> "nicer", "off", "Black girl dark", "Brown, Rich", "brown", "sm…
## $ t15     <chr> "dull", "present", "Looking for approval", "Sweet", "brown", "…
## $ t16     <chr> "light brown", "annoyed", "Dark far apart", "Pale brown, nice"…
## $ t17     <chr> "angry", "agresive hard big", "Weird brown bigger", "gold", "b…
## $ t18     <chr> "deep", "average", "Asian dark slanted", "brown, thin, beautif…
## $ t19     <chr> "mad", "aver as ge", "Small dark dead", "brown", "brown", "tir…
## $ t20     <chr> "blue", "mildlybsurprised", "Blue blank stare", "soft", "lobsi…
## $ t21     <chr> "dull", "indifferent", "Black girl blsck", "tired, brown", "an…
## $ t22     <chr> "upset", "indifference", "Dark tiny bitchy", "brown", "brown",…
## $ t23     <chr> "upset", "plotting", "Brown Asian looking", "brown, mean", "sq…
## $ t24     <chr> "depressing", "sympathetic", "Blue gray skeptical", "Amazing",…
## $ t25     <chr> "art", "indifferent", "Dark plain small", "weeeeeeeeee", "roun…
## $ t26     <chr> "deep", "direct", "Mexican dark big", "grey blue, small", "big…
## $ t27     <chr> "boring", "soft", "Asian bloodshot", "Brown, Pretty", "brown",…
## $ t28     <chr> "mixed", "irritable", "Gray blue white", "Grey, Blue, Green", …
## $ t29     <chr> "lost", "blunt", "Blood shot brown", "Brown", "brown", "nice",…
## $ t30     <chr> "dull", "bored dry", "Eyes look diff ways", "brown, clean", "b…
## $ t31     <chr> "empty", "focused", "Hazel maybe brown", "meh", "surprised,blu…
## $ t32     <chr> "dark", "intense focused cold", "Weird color alert", "soft", "…
## $ t33     <chr> "attractive", "submissive", "Blue crazy eyebrows", "Blue, dete…
## $ t34     <chr> "happy", "blank absent uninvolved", "Pale blue trusting", "per…
## $ t35     <chr> "very mad", "unmoved", "Dark blue drunk", "blind,", "old", "bl…
## $ t36     <chr> "open", "listening with concern", "Blue bags brows", "Clear, B…
## $ t37     <chr> "focused", "daring challenging calculating", "Dark cock eyed",…
## $ t38     <chr> "brown", "intense", "Dead dark saggy", "hopeful", "sad", "weir…
## $ t39     <chr> "sad", "searching pretty", "Blue trailer face", "Scared, uncom…
## $ t40     <chr> "focused", "demandin expectant", "Blue alien spaced", "Grey, b…
## $ t41     <chr> "light blue", "attentive", "Blue sassy tiny", "clear blue", "r…
## $ t42     <chr> "intersting,cute", "off", "Blue uneven face", "amazing", "blue…
## $ t43     <chr> "upset", "uninterested", "Black girl dark", "Serious, pretty",…
## $ t44     <chr> "interesting", "bright", "Asian cross eyed", "sweet, preppy", …
## $ t45     <chr> "lost", "unfocused", "Too far apart", "Perfect", "big", "sleep…
## $ t46     <chr> "determined", "confident confrontational", "Brown green pretty…
## $ t47     <chr> "confused", "judging", "Mexican eyed indian", "Dark, Deep, ama…
## $ t48     <chr> "full", "mean", "Blue drinker old", "Blue, Crazy", "blue", "bl…
## $ t49     <chr> "open", "almost flirty", "Blue cock eyed", "Blue, clear", "blu…
## $ t50     <chr> "no", "confused questioning", "White girl dark", "Confused, ne…

Create a dataset with separate columns for face_id, description, and description number (desc_n).

Hint: to separate a string by tildes or commas, you would set the sep argument to "(~|,)+".

HINT: to separate a string by tildes or commas, you would set the sep argument to "(~|,)+". You will need to apply this in one of the functions (this problem is best approached is pieces, with piping).

eyes <- eye_data |>
  rename(face_id = user_id) |>
  separate_rows(desc, sep = "\\s*[,;/]\\s*") |>
  mutate(desc = trimws(desc)) |>
  group_by(face_id) |>
  mutate(desc_n = row_number()) |>
  ungroup()
## Error in `separate_rows()`:
## ! Can't select columns that don't exist.
## ✖ Column `desc` doesn't exist.
glimpse(eyes)
## Error:
## ! object 'eyes' not found