7 - split-apply-combine(-review)

Author

Jacob Lahne

Published

June 24, 2026

Introduction

This week we are going to take a breath. We’ve covered a lot of material up to this point, and (writing this in the summer before the class has even begun) I will have sped through or even skipped over some material because I ran out of time. This week, we’re going to take the time to review that material and answer your questions.

We’re also going to leave time this week in our code session on Thursday to go over issues you’re having with your Data Analysis Report #1. Remember, it is due next Thursday!

Data Analysis Report #1

Remember that the rough draft for your data analysis report is due October 9, this Thursday. This means, like for any normal homework, that I want you to submit a good-faith first draft to the same assignment before class on Thursday.

Printing data nicely

For many of you, I’ve encouraged you to think about how to print data nicely once imported into R: not printing out 100+ lines of a data frame in a rendered file. Let’s look at a few ways to do that.

Today we’re going to work with the polyphenol data–again–and also take a look at the cider sorting data for some examples.

polyphenols <- read_csv("data/Week 4/polyphenol testing.csv")
Rows: 81 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (4): Catechin, PC B2, Chlorogenic acid, equivalents in gallic acid mg/L

ℹ 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.
cider_demo <- readxl::read_excel("data/cider sorting.xlsx", range = "A1185:AE1250")

If we print out these data frame and knit the file, it’s kind of ugly. For a real report, this wouldn’t be acceptable.

knitr::kable(polyphenols)
Catechin PC B2 Chlorogenic acid equivalents in gallic acid mg/L
0.2 1 5 2.79
0.2 1 5 2.73
0.2 1 5 2.74
0.2 1 200 57.73
0.2 1 200 58.19
0.2 1 200 69.24
0.2 1 500 150.31
0.2 1 500 161.70
0.2 1 500 161.13
0.2 30 5 15.17
0.2 30 5 15.27
0.2 30 5 14.01
0.2 30 200 63.54
0.2 30 200 64.00
0.2 30 200 62.40
0.2 30 500 168.25
0.2 30 500 159.71
0.2 30 500 136.65
0.2 100 5 46.57
0.2 100 5 46.12
0.2 100 5 50.90
0.2 100 200 95.32
0.2 100 200 92.36
0.2 100 200 84.16
0.2 100 500 148.32
0.2 100 500 158.29
0.2 100 500 157.43
30.0 1 5 14.01
30.0 1 5 13.80
30.0 1 5 13.87
30.0 1 200 60.01
30.0 1 200 51.92
30.0 1 200 65.14
30.0 1 500 170.24
30.0 1 500 173.38
30.0 1 500 170.53
30.0 30 5 21.93
30.0 30 5 17.97
30.0 30 5 17.32
30.0 30 200 57.28
30.0 30 200 52.04
30.0 30 200 50.33
30.0 30 500 155.44
30.0 30 500 153.16
30.0 30 500 158.00
30.0 100 5 52.38
30.0 100 5 51.47
30.0 100 5 52.61
30.0 100 200 115.58
30.0 100 200 117.57
30.0 100 200 116.43
30.0 100 500 119.56
30.0 100 500 130.38
30.0 100 500 118.71
100.0 1 5 44.75
100.0 1 5 45.32
100.0 1 5 44.98
100.0 1 200 56.37
100.0 1 200 56.14
100.0 1 200 57.39
100.0 1 500 131.52
100.0 1 500 138.64
100.0 1 500 136.36
100.0 30 5 50.67
100.0 30 5 51.92
100.0 30 5 50.79
100.0 30 200 56.82
100.0 30 200 63.43
100.0 30 200 66.85
100.0 30 500 143.19
100.0 30 500 153.45
100.0 30 500 143.19
100.0 100 5 56.03
100.0 100 5 56.94
100.0 100 5 56.14
100.0 100 200 121.55
100.0 100 200 115.58
100.0 100 200 118.71
100.0 100 500 151.17
100.0 100 500 145.19
100.0 100 500 151.45
knitr::kable(cider_demo)
Test_Name Section_Name Section_Number Sample_Set_Number Session_Number Session_Name Panelist_Code Panelist_Name Panelist_Display_Name Panelist_Email Q1__Gender Q1__Gender_COMMENTS Q1__Gender_Time_Stamp Q2__Age Q2__Age_Time_Stamp Q3__Purchase_cider Q3__Purchase_cider_Time_Stamp Q4__Cider_choice Q4__Cider_choice_Time_Stamp Q5__Drink_cider Q5__Drink_cider_Time_Stamp Q6__1__I_only_consume_hard_cider Q6__2__Wine_(red__white__sparkling_etc) Q6__3__Wine_coolers Q6__4__Beer Q6__5__Spirits_(whiskey__bourbon__vodka__rum__gin_etc) Q6__6__Liqueurs_(fruit__flower__cream__honey__etc_) Q6__7__Other(s):_please_indicate Q6__7__Other(s):_please_indicate_COMMENTS Q6___Time_Stamp QG:Hard Cider Consumption
102918_VA Cider Sort Second Section: Questionnaire 2 1 1 Session 1 cotrupi_vtu Catherine Cotrupi Catherine cotrupi@vt.edu 2 NA 2018-10-29 10:15:08 2 2018-10-29 10:15:11 3 2018-10-29 10:15:17 Taste, I prefer sweet and smooth- not bitter or hoppy 2018-10-29 10:15:58 4 2018-10-29 10:16:03 0 1 0 0 1 0 0 NA 2018-10-29 10:16:18 NA
102918_VA Cider Sort Second Section: Questionnaire 2 2 1 Session 1 kessingervi_vtu Vincent Kessinger Vincent kessingervi@outlook.com 1 NA 2018-10-29 10:17:27 2 2018-10-29 10:17:30 2 2018-10-29 10:17:36 Taste, sweetness and reputation of the cidery. 2018-10-29 10:18:30 3 2018-10-29 10:18:38 0 1 0 1 1 1 0 NA 2018-10-29 10:19:00 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 3 1 Session 1 kadieb_vtu Kadie Britt Kadie kadieb@vt.edu 2 NA 2018-10-29 10:49:55 1 2018-10-29 10:49:59 3 2018-10-29 10:50:07 I prefer a drier cider, or just one that is not extremely sweet. I judge by brand as well. I prefer one that is not Reddís or Angry Orchard, for example. I typically go for Bold Rock. 2018-10-29 10:52:01 4 2018-10-29 10:52:06 0 1 0 1 0 0 0 NA 2018-10-29 10:52:14 NA
102918_VA Cider Sort Second Section: Questionnaire 2 4 1 Session 1 tutene_vtu Evan Tuten Evan tutene@vt.edu 1 NA 2018-11-01 10:20:33 1 2018-11-01 10:20:35 1 2018-11-01 10:20:40 gotta be sweet 2018-11-01 10:21:01 2 2018-11-01 10:21:05 0 1 1 1 1 0 0 NA 2018-11-01 10:21:13 NA
102918_VA Cider Sort Second Section: Questionnaire 2 5 1 Session 1 hkissel2_vtu Heather Kissel Heather hkissel2@vt.edu 2 NA 2018-10-29 11:12:59 1 2018-10-29 11:13:03 3 2018-10-29 11:13:15 I am not a beer drinker, and like alcoholic beverages that are low alcohol content but still taste sweet and I love regular cider 2018-10-29 11:14:16 3 2018-10-29 11:14:30 0 1 1 0 1 1 0 NA 2018-10-29 11:14:49 NA
102918_VA Cider Sort Second Section: Questionnaire 2 6 1 Session 1 merri96_vtu Merrick Seltz Merrick merri96@vt.edu 1 NA 2018-10-29 11:12:04 1 2018-10-29 11:12:07 2 2018-10-29 11:12:15 Fruit aromas with no ìbarnyardî scent, effervescence and a dry finish 2018-10-29 11:13:20 2 2018-10-29 11:13:24 0 1 0 1 1 0 0 NA 2018-10-29 11:13:33 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 7 1 Session 1 camwalt_vtu Cameron Walton Cameron camwalt@vt.edu 1 NA 2018-10-29 11:18:12 1 2018-10-29 11:18:15 2 2018-10-29 11:18:22 Brand name. Always willing to try new cider, but I normally look for brand. 2018-10-29 11:19:55 3 2018-10-29 11:20:00 0 1 0 1 1 1 0 NA 2018-10-29 11:20:19 NA
102918_VA Cider Sort Second Section: Questionnaire 2 8 1 Session 1 ann.sandbrook@vt.edu Ann Sandbrook Ann ann.sandbrook@vt.edu 2 NA 2018-10-29 11:48:08 2 2018-10-29 11:48:15 2 2018-10-29 11:48:38 Type of cider: sparkling, dry, carbonated or sweet. If I want a cider more like a wine (still, dry or sparkling) or more like a beer (carbonated slightly sweet, lower ALC) 2018-10-29 11:50:19 3 2018-10-29 11:50:25 0 1 0 1 1 1 0 NA 2018-10-29 11:50:44 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 9 1 Session 1 Ksara1_vtu Sara Klopf Sara Ksara1@vt.edu 2 NA 2018-10-29 12:32:59 2 2018-10-29 12:33:02 2 2018-10-29 12:33:10 Not too sweet, good fresh apple flavor, not too strong alcohol 2018-10-29 12:33:43 2 2018-10-29 12:33:47 0 1 0 1 1 0 0 NA 2018-10-29 12:33:54 NA
102918_VA Cider Sort Second Section: Questionnaire 2 10 1 Session 1 dalego_vtu Dan Goerlich Dan dalego@vt.edu 1 NA 2018-10-29 12:24:39 3 2018-10-29 12:24:45 1 2018-10-29 12:24:57 I rarely consume hard cider. On the seldom occasions that I do, I look for a mellow taste, not bubbly, with a pleasant smell. 2018-10-29 12:27:11 2 2018-10-29 12:27:19 0 1 1 1 1 1 0 NA 2018-10-29 12:27:52 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 11 1 Session 1 mcrotto@vt.edu Michelle Crotto Michelle mcrotto@vt.edu 2 NA 2018-10-29 12:30:17 2 2018-10-29 12:30:21 2 2018-10-29 12:30:27 Taste 2018-10-29 12:30:40 3 2018-10-29 12:30:50 0 1 0 1 1 0 0 NA 2018-10-29 12:31:10 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 12 1 Session 1 Ericjd_vtu Eric Dinwiddie Eric Ericjd@vt.edu 1 NA 2018-10-29 12:55:51 2 2018-10-29 12:55:57 2 2018-10-29 12:56:06 Local, tradional 2018-10-29 12:56:45 2 2018-10-29 12:56:52 0 0 0 0 1 1 0 NA 2018-10-29 12:57:05 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 13 1 Session 1 paule19@vt.edu Paulette Cairns Paulette paule19@vt.edu 2 NA 2018-10-29 13:11:31 1 2018-10-29 13:11:34 2 2018-10-29 13:11:45 That it has a nice flavor and is not too sweet or too acidic. 2018-10-29 13:12:35 3 2018-10-29 13:12:42 0 1 0 1 1 1 0 NA 2018-10-29 13:12:53 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 14 1 Session 1 karisb_vtu Karis Boyd-Sinkler Karis karisb@vt.edu 2 NA 2018-10-29 13:11:15 1 2018-10-29 13:11:17 3 2018-10-29 13:11:23 Brand - I try to buy VA ciders based on the fact that I grew up in VA. Flavor type, cost, label 2018-10-29 13:12:51 3 2018-10-29 13:12:56 0 1 0 0 1 0 0 NA 2018-10-29 13:13:05 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 15 1 Session 1 Santosc_vtu Claire Santos Claire Santosc@vt.edu 2 NA 2018-10-29 13:18:31 3 2018-10-29 13:18:34 4 2018-10-29 13:18:45 Taste. Canít be dry or bitter 2018-10-29 13:19:21 5 2018-10-29 13:19:27 0 1 0 0 0 0 0 NA 2018-10-29 13:19:34 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 16 1 Session 1 jacuff_vtu Jennifer Acuff Jennifer jacuff@vt.edu 2 NA 2018-10-30 13:57:42 1 2018-10-30 13:57:47 2 2018-10-30 13:57:54 Variety of fruits (apple, pear) and less sweet flavor profiles, more crisp. 2018-10-30 13:59:14 2 2018-10-30 13:59:26 0 1 0 1 1 0 0 NA 2018-10-30 13:59:37 NA
102918_VA Cider Sort Second Section: Questionnaire 2 17 1 Session 1 Cherrie1_vtu Cherrie Rose Cherrie Cherrie1@vt.edu 2 NA 2018-10-29 13:28:10 2 2018-10-29 13:28:13 3 2018-10-29 13:28:18 Taste 2018-10-29 13:28:38 3 2018-10-29 13:28:45 0 1 1 0 1 1 0 NA 2018-10-29 13:29:05 NA
102918_VA Cider Sort Second Section: Questionnaire 2 18 1 Session 1 kdebose_vtu Kiri DeBose Kiri kdebose@vt.edu 2 NA 2018-10-29 14:04:18 3 2018-10-29 14:04:21 2 2018-10-29 14:04:27 I prefer those that are on the sweeter side with some noticeable apple flavor (prefer that taste to come at the end and linger a littleat the end). Like one that has a nice little kick to it as taste (as opppsed to flat) but not enough to throw one down and overwhelm the flavor itself. 2018-10-29 14:08:24 2 2018-10-29 14:08:30 0 1 0 0 1 0 0 NA 2018-10-29 14:08:52 NA
102918_VA Cider Sort Second Section: Questionnaire 2 19 1 Session 1 gibsonm@vt.edu Monika Gibson Monika gibsonm@vt.edu 2 NA 2018-10-30 10:31:37 4 2018-10-30 10:31:41 4 2018-10-30 10:31:50 No sweeteners; fresh, dry, fruity taste; interesting flavor combos if not plain apple cider 2018-10-30 10:33:43 5 2018-10-30 10:33:49 0 1 0 0 1 0 0 NA 2018-10-30 10:34:22 NA
102918_VA Cider Sort Second Section: Questionnaire 2 20 1 Session 1 wlauren_vtu Lauren Wind Lauren wlauren@vt.edu 2 NA 2018-10-30 10:21:41 1 2018-10-30 10:21:44 2 2018-10-30 10:21:49 Brewer location ie is it local 2018-10-30 10:22:27 3 2018-10-30 10:22:33 0 1 1 1 1 1 0 NA 2018-10-30 10:22:42 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 21 1 Session 1 mponder_vtu Monica Ponder Monica mponder@vt.edu 2 NA 2018-11-01 10:29:06 3 2018-11-01 10:29:10 2 2018-11-01 10:29:18 Price; drier styles more appealing, is the label pretty? 2018-11-01 10:30:05 3 2018-11-01 10:30:19 0 1 0 1 1 0 0 NA 2018-11-01 10:30:30 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 22 1 Session 1 ldouglas_vtu Laura Lawson Laura ldouglas@vt.edu 2 NA 2018-10-30 12:43:54 3 2018-10-30 12:43:58 2 2018-10-30 12:44:04 Pleasant smell with citrus and floral notes in taste 2018-10-30 12:45:13 3 2018-10-30 12:45:20 0 1 0 0 1 0 0 NA 2018-10-30 12:45:35 NA
102918_VA Cider Sort Second Section: Questionnaire 2 23 1 Session 1 ndbriggs_vtu Nathan Briggs Nathan ndbriggs@vt.edu 1 NA 2018-10-30 12:32:12 1 2018-10-30 12:32:15 3 2018-10-30 12:32:23 Dryness, heritage apples, funky-ness 2018-10-30 12:32:56 3 2018-10-30 12:33:03 0 1 0 1 1 0 0 NA 2018-10-30 12:33:19 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 24 1 Session 1 rachael.m.stone_vtu Rachael Stone Rachael rachael.m.stone@gmail.com 2 NA 2018-10-30 12:33:48 1 2018-10-30 12:33:52 2 2018-10-30 12:33:57 Sweet/dry 2018-10-30 12:34:18 3 2018-10-30 12:34:24 0 1 0 1 0 0 0 NA 2018-10-30 12:34:33 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 25 1 Session 1 babybug_vtu Beck Hall Beck babybug@vt.edu 3 Nonbinary 2018-10-30 12:37:22 1 2018-10-30 12:37:26 3 2018-10-30 12:37:34 Love horseblanket smell and feel - usually find it through trial and error - labels rarely indicate the feeling of the cider 2018-10-30 12:38:47 3 2018-10-30 12:38:54 0 1 0 1 1 0 0 NA 2018-10-30 12:39:09 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 26 1 Session 1 najlamk_vtu Najla Miranda Mouchrek Najla najlamk@vt.edu 2 NA 2018-10-30 13:22:39 3 2018-10-30 13:22:42 2 2018-10-30 13:22:50 I like it to be sweet, not too acid, and slightly sparkling. 2018-10-30 13:24:11 2 2018-10-30 13:24:17 0 1 0 1 0 0 0 NA 2018-10-30 13:24:29 NA
102918_VA Cider Sort Second Section: Questionnaire 2 27 1 Session 1 kswaby_vtu Keri Swaby Keri kswaby@vt.edu 2 NA 2018-10-30 13:11:01 3 2018-10-30 13:11:07 1 2018-10-30 13:11:16 N/a 2018-10-30 13:11:38 2 2018-10-30 13:11:48 0 1 0 1 1 0 0 NA 2018-10-30 13:12:28 NA
102918_VA Cider Sort Second Section: Questionnaire 2 28 1 Session 1 robynes_vtu Robyn Stuart Robyn robynes@vt.edu 2 NA 2018-10-30 13:05:09 2 2018-10-30 13:05:13 3 2018-10-30 13:05:23 Cost, source (i.e. local or craft), dry but flavorful 2018-10-30 13:06:32 5 2018-10-30 13:06:37 0 1 0 0 1 1 0 NA 2018-10-30 13:06:51 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 29 1 Session 1 cnproudfoot_vtu Chad Proudfoot Chad cnproudfoot@vt.edu 1 NA 2018-10-30 13:17:28 2 2018-10-30 13:17:32 2 2018-10-30 13:17:40 Tart, appealing taste 2018-10-30 13:18:09 3 2018-10-30 13:18:13 0 1 1 1 1 0 0 NA 2018-10-30 13:18:26 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 30 1 Session 1 jamiemcr_vtu James McReynolds James jamiemcr@vt.edu 1 NA 2018-10-30 13:35:27 5 2018-10-30 13:35:35 1 2018-10-30 13:35:48 Sweetness 2018-10-30 13:36:06 2 2018-10-30 13:36:12 0 1 1 1 1 1 0 NA 2018-10-30 13:36:26 NA
102918_VA Cider Sort Second Section: Questionnaire 2 31 1 Session 1 ahashimo_vtu Amanda Hashimoto Amanda ahashimo@vt.edu 2 NA 2018-10-30 13:45:05 1 2018-10-30 13:45:08 2 2018-10-30 13:45:18 Sweetness and more alcohol content 2018-10-30 13:46:00 2 2018-10-30 13:46:06 0 0 0 1 1 1 0 NA 2018-10-30 13:46:17 NA
102918_VA Cider Sort Second Section: Questionnaire 2 32 1 Session 1 sopint8_vtu Sophie Pinton Sophie sopint8@vt.edu 2 NA 2018-10-30 14:22:46 1 2018-10-30 14:22:50 1 2018-10-30 14:23:04 N/a 2018-10-30 14:24:30 3 2018-10-30 14:24:37 0 1 0 1 1 0 0 NA 2018-10-30 14:24:45 NA
102918_VA Cider Sort Second Section: Questionnaire 2 33 1 Session 1 aprussin_vtu AJ Prussin AJ aprussin@vt.edu 1 NA 2018-10-30 14:44:34 2 2018-10-30 14:44:37 2 2018-10-30 14:44:41 Being dry. I hate any added sugar or sweetness. 2018-10-30 14:45:28 2 2018-10-30 14:45:32 0 1 0 1 0 0 0 NA 2018-10-30 14:45:37 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 34 1 Session 1 roxi3_vtu Roxanne Smith Roxanne roxi3@vt.edu 2 NA 2018-10-30 14:22:28 1 2018-10-30 14:22:30 1 2018-10-30 14:22:36 Previous knowledge that itís not too sweet 2018-10-30 14:23:09 2 2018-10-30 14:23:15 0 1 0 1 1 0 0 NA 2018-10-30 14:23:30 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 35 1 Session 1 rachr15_vtu Rachel Rupnow Rachel rachr15@vt.edu 2 NA 2018-10-30 14:39:18 1 2018-10-30 14:39:21 2 2018-10-30 14:39:27 Prefer semisweet or sweet 2018-10-30 14:40:11 2 2018-10-30 14:40:25 0 1 0 1 1 0 0 NA 2018-10-30 14:40:42 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 36 1 Session 1 millercd@vt.edu Christina Miller Christina millercd@vt.edu 2 NA 2018-10-30 14:36:25 2 2018-10-30 14:36:30 2 2018-10-30 14:36:37 Interesting flavors, brand, price, flavors that arenít too sweet 2018-10-30 14:37:39 2 2018-10-30 14:37:43 0 1 0 1 1 0 0 NA 2018-10-30 14:37:53 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 37 1 Session 1 kwater_vtu Kim Waterman Kim kwater@vt.edu 2 NA 2018-10-30 14:56:05 4 2018-10-30 14:56:09 2 2018-10-30 14:56:17 Not too sweet, but with a good fruity note. Pretty labels! 2018-10-30 14:57:45 2 2018-10-30 14:57:51 0 0 0 0 1 0 0 NA 2018-10-30 14:58:03 NA
102918_VA Cider Sort Second Section: Questionnaire 2 38 1 Session 1 bwd_vtu Brett Driver Brett bwd@vt.edu 1 NA 2018-10-30 15:04:57 1 2018-10-30 15:05:03 1 2018-10-30 15:05:26 N/A 2018-10-30 15:05:47 2 2018-10-30 15:05:54 0 1 0 1 1 0 0 NA 2018-10-30 15:06:10 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 39 1 Session 1 trsjr_vtu Thomas Saunders Thomas trsjr@vt.edu 1 NA 2018-10-30 15:36:59 4 2018-10-30 15:37:06 2 2018-10-30 15:37:14 Price 2018-10-30 15:38:30 2 2018-10-30 15:38:38 0 1 0 1 1 0 0 NA 2018-10-30 15:38:57 NA
102918_VA Cider Sort Second Section: Questionnaire 2 40 1 Session 1 mswright@vt.edu Melissa Wright Melissa mswright@vt.edu 2 NA 2018-11-01 11:10:17 2 2018-11-01 11:10:21 2 2018-11-01 11:10:28 Bright, crisp flavor; light and refreshing; not too heavy or filling 2018-11-01 11:11:06 3 2018-11-01 11:11:11 0 1 0 1 1 0 0 NA 2018-11-01 11:11:22 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 41 1 Session 1 kaylalk_vtu Kayla Kipps Kayla kaylalk@vt.edu 2 NA 2018-10-30 15:35:02 1 2018-10-30 15:35:06 4 2018-10-30 15:35:13 Semi-sweet, low calorie 2018-10-30 15:35:37 5 2018-10-30 15:35:43 0 1 0 1 0 0 0 NA 2018-10-30 15:35:49 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 42 1 Session 1 elsheba_vtu Elsheba Abraham Elsheba elsheba@vt.edu 2 NA 2018-10-30 15:40:48 1 2018-10-30 15:40:50 2 2018-10-30 15:40:57 Taste more sweet and/or fruity 2018-10-30 15:41:36 2 2018-10-30 15:41:42 0 1 0 1 1 0 0 NA 2018-10-30 15:41:50 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 43 1 Session 1 plaura_vtu Laura Palmer Laura plaura@vt.edu 2 NA 2018-10-30 15:45:03 1 2018-10-30 15:45:09 2 2018-10-30 15:45:15 Sweetness, aftertaste, local 2018-10-30 15:45:51 3 2018-10-30 15:46:00 0 1 1 0 0 0 0 NA 2018-10-30 15:46:11 NA
102918_VA Cider Sort Second Section: Questionnaire 2 44 1 Session 1 tuckj21_vtu Jordan Tuck Jordan tuckj21@vt.edu 1 NA 2018-10-30 16:05:02 1 2018-10-30 16:05:07 3 2018-10-30 16:05:14 If I have had before (either to try something new or go with something I know I like) Price 2018-10-30 16:06:22 3 2018-10-30 16:06:36 0 0 0 1 1 0 0 NA 2018-10-30 16:06:46 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 45 1 Session 1 ihaugen@vt.edu Inga Haugen Inga ihaugen@vt.edu 2 NA 2018-11-01 11:32:56 2 2018-11-01 11:33:02 3 2018-11-01 11:33:09 Taste. Not too sweet, NOT hoppy, more dry and crisp. Local is a priority after taste. 2018-11-01 11:34:29 3 2018-11-01 11:34:41 0 0 0 1 1 0 0 NA 2018-11-01 11:34:54 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 46 1 Session 1 sihuima_vtu Sihui Ma Sihui sihuima@vt.edu 2 NA 2018-11-01 14:12:57 1 2018-11-01 14:13:00 2 2018-11-01 14:13:14 N/A 2018-11-01 14:13:33 2 2018-11-01 14:13:39 0 1 0 1 1 0 0 NA 2018-11-01 14:13:54 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 47 1 Session 1 ecoiley_vtu Erin Coiley Erin ecoiley@vt.edu 2 NA 2018-11-01 11:45:54 1 2018-11-01 11:45:57 3 2018-11-01 11:46:07 Pricing, brand, ingredients 2018-11-01 11:46:48 3 2018-11-01 11:46:56 0 1 1 0 1 0 0 NA 2018-11-01 11:47:08 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 48 1 Session 1 hpatton_vtu Hannah Patton Hannah hpatton@vt.edu 2 NA 2018-11-01 12:23:25 1 2018-11-01 12:23:28 3 2018-11-01 12:23:36 I like hard ciders in which you can really taste the fruit. I really enjoy apple and pineapple hard ciders for this reason. I also like when theyíre very carbonated and on the sour side as well. 2018-11-01 12:25:14 3 2018-11-01 12:25:19 0 1 0 0 1 1 0 NA 2018-11-01 12:25:31 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 49 1 Session 1 catie_cat_vtu Catie Pannill Catie catie_cat@me.com 2 NA 2018-11-01 12:21:25 1 2018-11-01 12:21:29 2 2018-11-01 12:21:40 Flavor and then origin 2018-11-01 12:22:40 3 2018-11-01 12:22:49 0 1 0 1 0 0 0 NA 2018-11-01 12:23:08 NA
102918_VA Cider Sort Second Section: Questionnaire 2 50 1 Session 1 Ashsuei1_vtu Ashley Iadonisi Ashley Ashsuei1@vt.edu 2 NA 2018-11-01 12:47:28 1 2018-11-01 12:47:31 2 2018-11-01 12:47:38 I like to go with a brand the someone recommended. I like ciders that taste like the fruit thatís advertised to be in them. I also tend to like more of a cinnamon flavor with them because I tend to drink them when itís cooler out. 2018-11-01 12:49:20 3 2018-11-01 12:49:25 0 1 0 1 1 1 0 NA 2018-11-01 12:49:35 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 51 1 Session 1 mgolusky_vtu Mark Golusky Mark mgolusky@vtti.vt.edu 1 NA 2018-11-01 12:55:17 3 2018-11-01 12:55:20 1 2018-11-01 12:55:27 N/A 2018-11-01 12:55:44 2 2018-11-01 12:55:50 0 1 0 1 1 0 0 NA 2018-11-01 12:56:01 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 52 1 Session 1 llyang@vt.edu Lily Yang Lily llyang@vt.edu 2 NA 2018-11-01 12:52:39 1 2018-11-01 12:52:41 2 2018-11-01 12:52:45 Style and brewery 2018-11-01 12:53:14 2 2018-11-01 12:53:20 0 1 0 1 1 1 0 NA 2018-11-01 12:53:32 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 53 1 Session 1 darya2_vtu Darya Evans Darya darya2@vt.edu 2 NA 2018-11-01 13:15:36 1 2018-11-01 13:15:39 3 2018-11-01 13:15:48 Stronger crisp apple flavor. But also economically appealing. 2018-11-01 13:16:42 3 2018-11-01 13:16:46 0 1 0 0 1 1 0 NA 2018-11-01 13:16:56 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 54 1 Session 1 groover_vtu Gordon groover Gordon groover@vt.edu 1 NA 2018-11-01 13:20:02 5 2018-11-01 13:20:07 2 2018-11-01 13:20:23 Taste 2018-11-01 13:20:47 4 2018-11-01 13:21:00 0 1 0 1 1 0 0 NA 2018-11-01 13:21:12 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 55 1 Session 1 rrboyer_vtu Renee Boyer Renee rrboyer@vt.edu 2 NA 2018-11-01 13:30:18 3 2018-11-01 13:30:23 3 2018-11-01 13:30:29 Flavor. I like dry, or semi sweet cider 2018-11-01 13:31:07 3 2018-11-01 13:31:15 0 1 0 0 1 0 0 NA 2018-11-01 13:31:23 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 56 1 Session 1 bvon_vtu Britannia Vondrasek Britannia bvon@vt.edu 2 NA 2018-11-01 13:37:06 1 2018-11-01 13:37:10 2 2018-11-01 13:37:17 Taste 2018-11-01 13:37:44 3 2018-11-01 13:37:52 0 1 0 0 1 1 0 NA 2018-11-01 13:38:12 NA
102918_VA Cider Sort Second Section: Questionnaire 2 57 1 Session 1 mike.zarella_vtu Mike Zarella Mike mike.zarella@gmail.com 1 NA 2018-11-01 13:57:40 2 2018-11-01 13:57:46 2 2018-11-01 13:57:59 Quality, dry 2018-11-01 13:59:24 2 2018-11-01 13:59:30 0 1 0 1 1 0 0 NA 2018-11-01 13:59:45 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 58 1 Session 1 mknox15_vtu Mackenzie Knox Mackenzie mknox15@vt.edu 2 NA 2018-11-01 14:20:01 1 2018-11-01 14:20:05 2 2018-11-01 14:20:12 The sweetness, the price, the flavor profile 2018-11-01 14:20:42 3 2018-11-01 14:20:47 0 1 0 0 1 1 0 NA 2018-11-01 14:20:59 NA
102918_VA Cider Sort Second Section: Questionnaire 2 59 1 Session 1 kaitr97_vtu Kaitlin Rosenberger Kaitlin kaitr97@vt.edu 2 NA 2018-11-01 14:20:04 1 2018-11-01 14:20:07 2 2018-11-01 14:20:13 Price is the most important factor, then sweetness and a strong apple flavor 2018-11-01 14:20:45 3 2018-11-01 14:20:50 0 1 0 1 0 0 0 NA 2018-11-01 14:21:01 NA
102918_VA Cider Sort Second Section: Questionnaire 2 60 1 Session 1 juliah_vtu Julia Horrocks Julia juliah@vt.edu 2 NA 2018-11-01 14:26:22 1 2018-11-01 14:26:25 3 2018-11-01 14:26:32 I like trying local ciders made from apples. 2018-11-01 14:27:20 3 2018-11-01 14:27:25 0 1 1 1 1 0 0 NA 2018-11-01 14:27:45 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 61 1 Session 1 atashi04_vtu Atashi Sharma Atashi atashi04@vt.edu 2 NA 2018-11-01 15:04:16 2 2018-11-01 15:04:19 4 2018-11-01 15:04:24 Should be sweet, fruity, not too strong smelling. 2018-11-01 15:04:54 4 2018-11-01 15:05:02 0 1 1 0 1 1 0 NA 2018-11-01 15:05:13 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 62 1 Session 1 lkburns_vtu Lisa Burns Lisa lkburns@vt.edu 2 NA 2018-11-01 15:12:21 3 2018-11-01 15:12:25 2 2018-11-01 15:12:31 Sweet flavor 2018-11-01 15:12:50 3 2018-11-01 15:12:55 1 1 0 1 0 0 0 NA 2018-11-01 15:13:05 NA
102918_VA Cider Sort Second Section: Questionnaire 2 63 1 Session 1 lblanc_vtu Lori Blanc Lori lblanc@vt.edu 2 NA 2018-11-01 15:22:49 3 2018-11-01 15:22:53 2 2018-11-01 15:23:01 It is rare that I buy cider, so I probably just go with a combination of what is available and the label (or recommendations by friends) 2018-11-01 15:24:25 2 2018-11-01 15:24:29 0 1 0 1 1 1 0 NA 2018-11-01 15:24:40 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 64 1 Session 1 velvag_vtu Velva Groover Velva velvag@vt.edu 2 NA 2018-11-01 15:59:32 4 2018-11-01 15:59:35 2 2018-11-01 15:59:46 Less sweet cider that is fruity tasting 2018-11-01 16:00:33 4 2018-11-01 16:00:47 0 1 0 1 1 0 0 NA 2018-11-01 16:01:00 Yes
102918_VA Cider Sort Second Section: Questionnaire 2 65 1 Session 1 wrightrc_vtu Clay Wright Clay wrightrc@vt.edu 1 NA 2018-11-01 15:53:22 2 2018-11-01 15:53:26 2 2018-11-01 15:53:32 I normally purchase dry ciders by the pint when a local or small cider maker is on tap at a brewery/bar/restaurant 2018-11-01 15:55:44 3 2018-11-01 15:55:52 0 1 0 1 1 0 1 Mead, sake, kombucha 2018-11-01 15:56:38 Yes

By default, tibbles will behave well and print out only the first couple lines:

polyphenols
# A tibble: 81 × 4
   Catechin `PC B2` `Chlorogenic acid` `equivalents in gallic acid mg/L`
      <dbl>   <dbl>              <dbl>                             <dbl>
 1      0.2       1                  5                              2.79
 2      0.2       1                  5                              2.73
 3      0.2       1                  5                              2.74
 4      0.2       1                200                             57.7 
 5      0.2       1                200                             58.2 
 6      0.2       1                200                             69.2 
 7      0.2       1                500                            150.  
 8      0.2       1                500                            162.  
 9      0.2       1                500                            161.  
10      0.2      30                  5                             15.2 
# ℹ 71 more rows

But if we want this to look nice, we might want to get an actual kable out of the tibble without printing all too many lines.

There are a couple options: head(), slice_head(), or setting options(knitr.kable.max_rows = n) to some small n.

slice_head()

The slice_head() function is the tidyverse version of head(). It is nice because it works on grouped data.

BONUS MARKDOWN

strikethrough

Material from Week 4–“split-apply-combine” and convenience

Split-apply-combine: group_by(), count(), and summarize()

We are only scratching the surface of what we can do with tidyverse, and you will both be reading more about this and we’ll be returning throughout the semester as we learn more application. But here is an exploratory data analysis application that we will see here and will come back to us frequently.

The group_by() function takes a data frame and groups it by whatever variable is specified. It looks for distinct values, so it will work with even numeric variables (although not well, if they are not truly grouping variables, such as actual observed values).

polyphenols |>
  group_by(Catechin) # note no quotes
# A tibble: 81 × 4
# Groups:   Catechin [3]
   Catechin `PC B2` `Chlorogenic acid` `equivalents in gallic acid mg/L`
      <dbl>   <dbl>              <dbl>                             <dbl>
 1      0.2       1                  5                              2.79
 2      0.2       1                  5                              2.73
 3      0.2       1                  5                              2.74
 4      0.2       1                200                             57.7 
 5      0.2       1                200                             58.2 
 6      0.2       1                200                             69.2 
 7      0.2       1                500                            150.  
 8      0.2       1                500                            162.  
 9      0.2       1                500                            161.  
10      0.2      30                  5                             15.2 
# ℹ 71 more rows

By itself, this does not appear to do anything, although if you look closely at the output from printing the tibble you’ll notice that it now lists Groups: Catechin [3].

We can use this to split the tibble into groups and do things to each group. For example, the n() function gives the number of rows in a group within a tibble (when used in mutate(), etc) and so, if we have 3 groups, n() will tell us for each group how many rows are in that group:

polyphenols |>
  group_by(Catechin) |>
  mutate(number_of_rows = n())
# A tibble: 81 × 5
# Groups:   Catechin [3]
   Catechin `PC B2` `Chlorogenic acid` equivalents in gallic ac…¹ number_of_rows
      <dbl>   <dbl>              <dbl>                      <dbl>          <int>
 1      0.2       1                  5                       2.79             27
 2      0.2       1                  5                       2.73             27
 3      0.2       1                  5                       2.74             27
 4      0.2       1                200                      57.7              27
 5      0.2       1                200                      58.2              27
 6      0.2       1                200                      69.2              27
 7      0.2       1                500                     150.               27
 8      0.2       1                500                     162.               27
 9      0.2       1                500                     161.               27
10      0.2      30                  5                      15.2              27
# ℹ 71 more rows
# ℹ abbreviated name: ¹​`equivalents in gallic acid mg/L`

…of course, this is very boring because this is a balanced factorial-design experiment with complete data, so each group of Catechin levels has 27 rows!

But this now allows us to use filter(), mutate(), and a host of other tidyverse functions in “grouped” mode, which means when we do all of those they will act WITHIN the group you have defined. So we can see the effect, we will first filter polyphenols, and then create a new variable with a grouped mutate() that is the average for that group.

polyphenols |>
  # this is purely for ease of printing this example
  filter(`Chlorogenic acid` == 5) |> 
  group_by(Catechin) |>
  mutate(average_eq_gc = mean(`equivalents in gallic acid mg/L`))
# A tibble: 27 × 5
# Groups:   Catechin [3]
   Catechin `PC B2` `Chlorogenic acid` equivalents in gallic aci…¹ average_eq_gc
      <dbl>   <dbl>              <dbl>                       <dbl>         <dbl>
 1      0.2       1                  5                        2.79          21.8
 2      0.2       1                  5                        2.73          21.8
 3      0.2       1                  5                        2.74          21.8
 4      0.2      30                  5                       15.2           21.8
 5      0.2      30                  5                       15.3           21.8
 6      0.2      30                  5                       14.0           21.8
 7      0.2     100                  5                       46.6           21.8
 8      0.2     100                  5                       46.1           21.8
 9      0.2     100                  5                       50.9           21.8
10     30         1                  5                       14.0           28.4
# ℹ 17 more rows
# ℹ abbreviated name: ¹​`equivalents in gallic acid mg/L`

But that’s not all! Now that we have the idea of a group, we can use it for all kinds of useful things. For example, the count() function will just return the number of rows in each group. Let’s use that to check if our polyphenols was from a balanced design (e.g., has the same number of observations at every treatment level and intersection):

polyphenols |>
  # note that we can group by multiple variables
  group_by(Catechin, `Chlorogenic acid`, `PC B2`) |> 
  # looks balanced, with triplicates at every treatment factor level
  count() 
# A tibble: 27 × 4
# Groups:   Catechin, Chlorogenic acid, PC B2 [27]
   Catechin `Chlorogenic acid` `PC B2`     n
      <dbl>              <dbl>   <dbl> <int>
 1      0.2                  5       1     3
 2      0.2                  5      30     3
 3      0.2                  5     100     3
 4      0.2                200       1     3
 5      0.2                200      30     3
 6      0.2                200     100     3
 7      0.2                500       1     3
 8      0.2                500      30     3
 9      0.2                500     100     3
10     30                    5       1     3
# ℹ 17 more rows

The count() function gets way more useful when we have large data that is unbalanced, and we want to be able to easily pull counts without knowing what they are beforehand.

Much more useful, but slightly more complex is the summarize() function, which applies arbitrary summary functions to the subsets defined by group_by(). So, say we want to find the average and standard deviation at each of the groups we defined before, instead of the count:

polyphenols |>
  group_by(Catechin, `PC B2`, `Chlorogenic acid`) |>
  summarize(mean_eq_gc = mean(`equivalents in gallic acid mg/L`),
            sd_eq_gc = sd(`equivalents in gallic acid mg/L`))
# A tibble: 27 × 5
# Groups:   Catechin, PC B2 [9]
   Catechin `PC B2` `Chlorogenic acid` mean_eq_gc sd_eq_gc
      <dbl>   <dbl>              <dbl>      <dbl>    <dbl>
 1      0.2       1                  5       2.75   0.0321
 2      0.2       1                200      61.7    6.52  
 3      0.2       1                500     158.     6.42  
 4      0.2      30                  5      14.8    0.700 
 5      0.2      30                200      63.3    0.824 
 6      0.2      30                500     155.    16.3   
 7      0.2     100                  5      47.9    2.64  
 8      0.2     100                200      90.6    5.78  
 9      0.2     100                500     155.     5.52  
10     30         1                  5      13.9    0.107 
# ℹ 17 more rows

Even I think that’s pretty cool, and I wrote the code! This can be a bit tricky to get your head around, so let’s talk through it.

The key intuition is that summarize() takes multiple rows, identified by the same grouping variable (here the triplicate measurement reps identified by the combinations of treatment variables) and applies a function to each group that returns a single number: remember that mean() gives the mean (average) of a set of numeric observations, and sd() gives the standard deviaiton.

NB: One final tip: you can always run part of a piped data flow by selecting just that part and hitting “run” in the right top corner of your RStudio coding panel or hitting ctrl/cmd + enter. This is useful for testing your code flow.

Utilities for data management

Honestly, the amount of power in tidyverse is way more than we can cover today, and is covered more comprehensively (obviously) by Wickham and Grolemund (2017), including your reading for this week. Instead, I want to draw attention to a few “quality of life” functions that tidyverse also provides that make tasks that are overly difficult in R a little easier.

rename()

A common need in data analysis is renaming your columns, because they are called something clear but not machine-readable/easily typable in your data file, and they turn into a mess in R. We have that problem in our polyphenols dataset:

names(polyphenols)
[1] "Catechin"                        "PC B2"                          
[3] "Chlorogenic acid"                "equivalents in gallic acid mg/L"

Even with tab-completion, those are a pain to deal with. Renaming these in base R is a huge pain, in fact. You can copy them to a new column by using the <- operator, then remove the original column using the [] operator with negative indices. Or you can use the names() <- operator. Neither is very easy to do on the fly.

In tidyverse, the rename() function is there to help. It works in two, equally useful ways.

# New names go on the left hand side, old names on the right
polyphenols |>
  rename(chlor = `Chlorogenic acid`,
         pcb2 = `PC B2`,
         cat = Catechin,
         eq_ga = `equivalents in gallic acid mg/L`)
# A tibble: 81 × 4
     cat  pcb2 chlor  eq_ga
   <dbl> <dbl> <dbl>  <dbl>
 1   0.2     1     5   2.79
 2   0.2     1     5   2.73
 3   0.2     1     5   2.74
 4   0.2     1   200  57.7 
 5   0.2     1   200  58.2 
 6   0.2     1   200  69.2 
 7   0.2     1   500 150.  
 8   0.2     1   500 162.  
 9   0.2     1   500 161.  
10   0.2    30     5  15.2 
# ℹ 71 more rows
# Alternatively, we can rename by INDEX, with new name on the left and column #
# on the right.  This is easier for programming, but is less safe because you
# have to be certain you're matching columns correctly.


# don't forget we have to actually save the changes if we want them to stick
polyphenols <- 
  polyphenols |> 
  rename(cat = 1, pcb2 = 2, chlor = 3, eq_ga = 4)

arrange()

Another thing we often want to do is sort the rows of a data table according to some criterion. Doing this in base R requires the use of sort(), which works only on vectors, not on data frames, and so requires a similar approach to the base R filtering approach we saw above.

The tidyverse version is very simple: arrange() just requires that you tell it a data frame and one or more columns to sort by.

# we'll use the soups data for this next bit
soups <- read_csv("data/Week 4/soup pilot data.csv")
Rows: 24 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (5): subject, minestrone1, minestrone2, hotandsour1, hotandsour2

ℹ 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.
# show us the data in ascending order of liking for hotandsour1
soups |>
  arrange(hotandsour1) 
# A tibble: 24 × 5
   subject minestrone1 minestrone2 hotandsour1 hotandsour2
     <dbl>       <dbl>       <dbl>       <dbl>       <dbl>
 1      12          75          25        -100        -100
 2      21          20         100        -100          60
 3      23          10         100        -100          85
 4       4          20          60         -80          65
 5      13         -25          50         -75         -10
 6      14          20          40         -75          60
 7       9          40          90         -60          20
 8      18          40          90         -60         -15
 9      22          20          60         -60         -10
10       1           0          50         -50          10
# ℹ 14 more rows
# writing "-" before the sorting column goes in descending order
soups |>
  arrange(-hotandsour1) 
# A tibble: 24 × 5
   subject minestrone1 minestrone2 hotandsour1 hotandsour2
     <dbl>       <dbl>       <dbl>       <dbl>       <dbl>
 1       8          70          80          50         -10
 2       7          75          90          40          80
 3       5          65          96          37          99
 4      24          10          75          35          55
 5      17          15          90          30          50
 6      10          15          65          25          20
 7       3          80          97          10          37
 8      11         -50          75         -15          50
 9       2          70          80         -20          20
10      15          70          90         -25         -60
# ℹ 14 more rows
# this sorts first ascending by hotandsour1, then within that descending by hotandsour2
soups |>
  arrange(hotandsour1, -hotandsour2) 
# A tibble: 24 × 5
   subject minestrone1 minestrone2 hotandsour1 hotandsour2
     <dbl>       <dbl>       <dbl>       <dbl>       <dbl>
 1      23          10         100        -100          85
 2      21          20         100        -100          60
 3      12          75          25        -100        -100
 4       4          20          60         -80          65
 5      14          20          40         -75          60
 6      13         -25          50         -75         -10
 7       9          40          90         -60          20
 8      22          20          60         -60         -10
 9      18          40          90         -60         -15
10      16          20          90         -50          30
# ℹ 14 more rows

relocate()

R doesn’t really care about the order of columns in a data frame, but we might, for example

  1. If we have a lot of columns, they might not print properly in the console, requiring some work every time we want to check their values.
  2. We might be outputting data to a knitr::kable() or other display mode

We can reorder columns using similar syntax to our base R select operations above, but this requires many steps. Again, the simple tidyverse solution is a single function: relocate():

# by default the column(s) are moved to the "front" of the table
soups |>
  relocate(hotandsour2) 
# A tibble: 24 × 5
   hotandsour2 subject minestrone1 minestrone2 hotandsour1
         <dbl>   <dbl>       <dbl>       <dbl>       <dbl>
 1          10       1           0          50         -50
 2          20       2          70          80         -20
 3          37       3          80          97          10
 4          65       4          20          60         -80
 5          99       5          65          96          37
 6          20       6          30          80         -50
 7          80       7          75          90          40
 8         -10       8          70          80          50
 9          20       9          40          90         -60
10          20      10          15          65          25
# ℹ 14 more rows
# .before and .after (note the ".") can be used to move to specific spots
soups |>
  relocate(hotandsour2, .after = subject) 
# A tibble: 24 × 5
   subject hotandsour2 minestrone1 minestrone2 hotandsour1
     <dbl>       <dbl>       <dbl>       <dbl>       <dbl>
 1       1          10           0          50         -50
 2       2          20          70          80         -20
 3       3          37          80          97          10
 4       4          65          20          60         -80
 5       5          99          65          96          37
 6       6          20          30          80         -50
 7       7          80          75          90          40
 8       8         -10          70          80          50
 9       9          20          40          90         -60
10      10          20          15          65          25
# ℹ 14 more rows

And on to Week 8–sprinting forward!

Session Info

R version 4.5.3 (2026-03-11)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.5.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] tictoc_1.2.1    lubridate_1.9.5 forcats_1.0.1   stringr_1.6.0  
 [5] dplyr_1.2.1     purrr_1.2.2     readr_2.2.0     tidyr_1.3.2    
 [9] tibble_3.3.1    ggplot2_4.0.2   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] rematch_2.0.0      bit_4.6.0          gtable_0.3.6       jsonlite_2.0.0    
 [5] crayon_1.5.3       compiler_4.5.3     tidyselect_1.2.1   parallel_4.5.3    
 [9] scales_1.4.0       readxl_1.4.5       yaml_2.3.12        fastmap_1.2.0     
[13] R6_2.6.1           generics_0.1.4     knitr_1.51         htmlwidgets_1.6.4 
[17] pillar_1.11.1      RColorBrewer_1.1-3 tzdb_0.5.0         rlang_1.2.0       
[21] stringi_1.8.7      xfun_0.57          S7_0.2.1           bit64_4.6.0-1     
[25] otel_0.2.0         timechange_0.4.0   cli_3.6.6          withr_3.0.2       
[29] magrittr_2.0.5     digest_0.6.39      grid_4.5.3         vroom_1.7.1       
[33] rstudioapi_0.18.0  hms_1.1.4          lifecycle_1.0.5    vctrs_0.7.3       
[37] evaluate_1.0.5     glue_1.8.1         cellranger_1.1.0   farver_2.1.2      
[41] rmarkdown_2.31     tools_4.5.3        pkgconfig_2.0.3    htmltools_0.5.9   

References

Wickham, Hadley, and Garrett Grolemund. 2017. R for Data Science. O’Reilly.