# 70 students as of Feb 1
students <- c("aavery2","adimasagurto","aflores-hernandez","ahmiyasalter",
"akwong25","alannahtanner","aleroux","alizeibarra","apatterson9",
"asingh368","bdelacruz-angeles","bhernandezarteaga","cbettencourt2",
"cchen271","cornelas3","craigelijaesoriano","davila-castaneda",
"dvargas38","ecastillo-quevedo","efernando","eflores136","ekjotjohal",
"elliottwhitney","elmermartinez","emendozagonzalez","emoya8",
"fromerobojorquez","genaxiong","ggonzalez-ramirez","ghendrickson",
"gurindersahota","isidrohernandez","jangel15","jardindo",
"jasminesamayoa","jessecaclark","jessiemorales","jlegaspina",
"jmandujano4","joneal2","jperez460","jwong290","kamryntaylor",
"kchen129","kchen132","kvu56","lalagos","leogarciaortiz",
"lillieyang","lindaespinozamunoz","lorenackerman","malachifuqua",
"manroopkaur","mayraarias","mdesilva","msuccari","omarkhalil",
"rbeattie","rbujji","roderickma","seanjimenez","skodur","sraman7",
"tolaniyan","treasureclasson","trevoroh","vchezhiyan","xcortes2")
language_table_students <- c("edmondcheng", "angeliachunyu")
teamsize <- 7
# Set seed for reproducibility
set.seed("20260202")
shuffled <- sample(students, replace = FALSE)
#tables <- ceiling(seq_along(shuffled) / teamsize)
tables <- c(rep(1:6,each=teamsize),rep(7,5),rep(8:10,each=7))
teams <- split(shuffled, tables)
teams$`7` <- c(teams$`7`,language_table_students)
invisible(lapply(seq_along(teams), function(i) {
cat("Team at Table", i, ":", teams[[i]], "\n")
}))
## Team at Table 1 : fromerobojorquez seanjimenez ecastillo-quevedo manroopkaur bhernandezarteaga lorenackerman akwong25
## Team at Table 2 : asingh368 xcortes2 ahmiyasalter jardindo jessecaclark lillieyang kamryntaylor
## Team at Table 3 : sraman7 alizeibarra leogarciaortiz apatterson9 ghendrickson jangel15 bdelacruz-angeles
## Team at Table 4 : emendozagonzalez efernando elmermartinez lindaespinozamunoz jwong290 skodur jessiemorales
## Team at Table 5 : genaxiong kchen129 jperez460 malachifuqua aflores-hernandez cchen271 treasureclasson
## Team at Table 6 : davila-castaneda craigelijaesoriano vchezhiyan cbettencourt2 ggonzalez-ramirez jmandujano4 eflores136
## Team at Table 7 : tolaniyan trevoroh alannahtanner kchen132 rbeattie edmondcheng angeliachunyu
## Team at Table 8 : aavery2 omarkhalil mdesilva jasminesamayoa gurindersahota dvargas38 cornelas3
## Team at Table 9 : adimasagurto aleroux mayraarias lalagos joneal2 emoya8 roderickma
## Team at Table 10 : ekjotjohal elliottwhitney isidrohernandez msuccari kvu56 rbujji jlegaspinaDSC 011 S26 Lecture 6 Workbook
Team Building Exercises and Interests Survey; Practice with Coding in the R REPL
Preliminaries and Instructions
Assignment of Teams and Team Tables
The class will split into randomly assigned teams of about seven. The teams and team tables are determined by random sampling without replacement (also known as permutation) as follows:
Instructions for this Demo
- Please be sure that you have been counted for your attendance by course instructors at the beginning or end of this lab. You cannot receive credit unless you are marked as Present.
- Download the template notebook for this Demo from CatCourses to your computer.
- Open the template notebook in RStudio application on your laptop, or uploaded it to your RStudio Server instance on the JupyterHub.
- Rename the file. In the RStudio/RStudio Server menus at the top of the application, please select
File -> Renameto rename the template notebook file to include your first and last name replacingFirstName_LastNamein the filename, to personalize it. - Personalize the notebook by adding your name in the YAML header at the top. Inside the Source Pane of RStudio, within the YAML header at the top of the notebook, find the key called
author:and, after the space character, change this key’s value by filling in your actual name inside the double quotation marks ("), replacing justFirstName LastName. - Save the notebook file. If you are using RStudio on your own laptop, at the top of the application, select
File -> Save as...to save your renamed and edited assignment notebook together where you keep your other files in this course. The tab for your worked assignment in the Source Pane should turn from red to black. - IMPORTANT: Now try to render the file. IF THE FILE DOESN”T RENDER, AND INSTEAD THROWS AN ERROR, PLEASE ask for help from team-mates and instructors. Scroll up in the lower-left
Background Jobstab of the R Console Pane for red-colored Error output describing the error. Discuss what it means with your team-mates and instructors and interpret why the error may be occurring, - Read the rendered notebook to understand and follow the assignment instructions, switching between the rendered HTML for instructions and your RStudio Source Pane to edit your assignment.
- Edit the notebook very carefully to avoid introducing markdown syntax errors. Render the notebook after each problem or question, after you enter your answers and solutions into the notebook, to avoid typos that prevent your notebook from rendering. Try to undo edits (using menu selection
Edit -> Undoand re-render to experiment to see if you can restore the ability of the notebook to render. As a last resort, start over with a fresh copy of the template and save your new version with a new name. Open both versions of your notebook, and carefully and systematically transfer your work to the new copy, testing that it can still render as you go. - Complete the assignment as instructed, asking for help and offering tips and help as you go to your team-mates. If you finish early, remain with your team and offer them help.
- Work with code in the R Console until it runs without errors and gives the correct solution. Once it works, copy your solution R code expression or expressions inside the problem’s answer code chunk as the right-hand side (RHS) of the assignment statement to the variable called
answer, and render the notebook to check the correctness of your solution. Correct solutions will be labelled CORRECT and incorrect solutions will be labelled INCORRECT. Try to get every solution to read CORRECT. - Please acknowledge team-mates and AI agents who particularly helped you in the Acknowledgements section of the notebook below.
- By the end of lecture or lab, turn in your rendered notebook in HTML format to CatCourses, even if it is only incompletely or partially worked, in order to be able to get credit for the demo assignment and resubmit later the fully worked and corrected assignment for full credit You may then try to finish the assignment until midnight tonight and resubmit an unlimited number of corrections for full credit on CatCourses by 11:59 pm this evening, as we only grade the most recent submission. Please ask for help on slack regarding help with errors or solutions. Provided that you turn in your notebook on CatCourses today, you may be able to submit corrections to it on later days by Slack at the discretion of the instructors. > To export HTML from the RStudio Server: navigate to the lower right File Pane and select the
Filestab. Select the checkmark next to the HTML export (with a little world icon) for this assignment! Then in the menu of that pane, selectmore...menu andexportand then select theDownloadbutton in the pop-up wizard that appears. The rendered quarto notebook in HTML format should be downloaded now to your Downloads folder for you to upload to CatCourses.
Acknowledgements
In this section please explicitly acknowledge by name the teammates or AI agents that helped you work this assignment, and please briefly describe how they helped you.
- Team-mate1 pointed out the man page…
- Team-mate2 showed me where to download…
- I used ChatGPT to check my code syntax…
Purpose of This Assignment and What You Will Learn
At the beginning of lecture, you and your team will introduce yourselves and discuss how to work better as a team. You are asked to edit the text with your answers inside the notebook and then share your answers with your team.
Then, we’ll pick up where we left off last time exploring how to use the R Console and R REPL to work with and better understand R code and the R REPL. In the course of this exploration, we will learn by doing about:
- Character vectors in R
- The
sample()function in R and how its used to randomly assign students to teams in this class. - The importance of setting a random seed for the R (Pseudo-)Random Number Generator (RNG) to achieve reproducibility of sampling and other random algorithms.
- What the
seq-along()andceiling()functions do, and how we combine them using function composition. - What the
c()andrep()functions do and how we can combine them to construct long vectors of integers. - Lists in R and how to construct them from vectors using
split() - Selecting and modifying list elements with the R selection operator (
$) - Appending to a vector with assignment using the
c()function. - Mapping a function to all of the elements of a list using the
lapply()function. - Anonymous (nameless) functions with the
function()function.
Assignment
Course Entrance Survey, Practice Editing Markdown and Team-Building Exercises
Please edit this section inside the Source pane of RStudio. Enter plain text inside each section to answer the questions in 1-3 brief sentences. Then, after you answered all of the questions, go around the table of your team, introduce yourself and share what you wrote here.
What year are you at UC Merced, and what is your declared or intended Major and/or Minor? Why are you taking this class?
I’m a first-year at UC Merced with a declared major of Electrical Engineering. I’m taking this class to get rid of two of my General Ed requirements.
Where did you live before coming to Merced, and what is a fun fact about you?
I lived in a city called Van Nuys where I grew up for around 12 years. I’m currently working on a video series with my friend right now.
What kind of Laptop are you using? How is the class going for you so far? What concepts and skills do you need help with?
I have a Dell Laptop and this class is growing overwhelmingly hard to say the least since I registered last Thursday. Most of the concepts, if not all, are proving to be a problem due to the fact of me registering late.
How would you like to work with your team today in order to better complete this assignment? How would you like to ask for help when you need it? What do you need to feel safe and included as a team member?
I’m not much a of go-getter, let alone a team member, so my only requirement to feel apart of the team is to be asked questions to regularly.
Using the R REPL to Understand what R Expressions Do and to Code in R
When we program R in RStudio, we use the R Console and REPL to work interactively in a conversation with the R Interpreter to draft, test, validate and debug R codes, by examining the values that we obtain from running those codes. Let’s practice using the R REPL to examine how the R code in the R code chunk above labelled teams works to assigns students to teams and see how it works.
Experiment with R Code in the R REPL
Setting the PRNG Seed to Reproduce a Specific Random Sample in R
We will pickup from Friday’s lecture to examine how the R code in the code chunk above works to randomly assign students to teams and team tables, using the sample() function.
- Recall from Friday’s lecture that in order to exactly reproduce the specific permutation of student IDs giving our team/table assignments today, you need to set the seed of the Pseudo-Random Number Generator (PRNG) with a specific value using the
set.seed()function, as shown at the top of the code chunk. - Down in the R Console, evaluate the name
shuffledto see today’s permutation of the student ID list printed as a character vector. Notice that when you render the notebook, the variables that get created in the code chunk persist in the environment of the Session R Interpreter, and can be referenced in the Console. - Now down in the R Console, copy the right-hand side of the R assignment in line 65 (starting
sample(to show that if you run this function again, you get a different permutation of students. - Now copy the expression from the code chunk in line 64 with
set.seed()into the R Console and run it. - Now in the R Console, press the
up-arrowkey twice to recall the call tosample()and see that it now produces the same permutation as the value ofshuffled - In the code chunk below, enter code to set the PRNG seed like you did in the console, and assign
answerto the return value ofsample()to recover today’s vector of shuffled student IDs.
answer <- NULL
print_and_check(answer,"9d9c7c26e14bf89d916a1292cc0b6a13")
## NULL
## [1] "INCORRECT"Compactly Generating Table Assignments; Modifying R Code in the Console
- Evaluate the code
c(rep(1:6,each=7),rep(7,5),rep(8:10,7))by copying and pasting it into the R Console to see what it returns. These are the table assignments for students. Is the output consistent and easy to understand? - Use the Up-arrow to recall this expression in the R Console, and examine the code for consistency. Modify the R expression so that students are assigned to tables in contigiuous blocks, also for tables 8 through 10.
- After you get it to look good in the Console, copy your corrected R expression and assign its value to
answerin the code chunk below.
answer <- NULL
print_and_check(answer,"2e27e2fe2bf18f0117e91fee22185be6")
## NULL
## [1] "INCORRECT"Splitting a Vector into a List of Vectors
- Evaluate the code
split(shuffled,tables)by copying and pasting it into the R Console to see what it returns. Here the shuffled students vector is split into an R list of character vectors, one vector for each team. - Copy this code and assign its value to
answerin the code chunk below.
answer <- NULL
print_and_check(answer,"979b7da9cd79cd816b035efba0af83bd")
## NULL
## [1] "INCORRECT"Selecting an Element of a List by its Name
- Evaluate the code on the left-hand side (LHS) of the assignment on line 69 by copying and pasting it into the R Console to see what it returns. This code should extract the character vector at the seventh item in the list called
teams. The7needs to be surrounded by backticks (because list element names in R are not allowed to start with digits). - Now use up-arrow in the R Console and modify the expression to extract the 8th team/character vector item in the
teamslist instead of the seventh. - When you get this to work, copy the modified code and assign its value to
answerin the code chunk below.
answer <- NULL
print_and_check(answer,"4784e4b587e46f750f58defa87548f28")
## NULL
## [1] "INCORRECT"Test Your Understanding
- In the R Console, practice using the R concatenation function
c()to concatenate the vectorsstudentsandlanguage_table_studentsin that order using their names, not their values. Once you get this to work, replaceNULLwith your working expression in the code chunk immediately below this paragraph in your quarto notebook to assign the value to the new character vector namedall_students.
all_students <- NULL
answer <- all_students
print_and_check(answer,"dbe36e6d941a58e0a259788d352c2bc5")
## NULL
## [1] "INCORRECT"Shuffling Character Vectors and Setting Seeds
R has built-in character vectors called letters and LETTERS containing the 26 letters of the English alphabet in lower or upper case. Try evaluating LETTERS in the R Console to see this.
Now in the R Console, use the
set.seed()function to set the seed to today’s date"20260202", and then modify the code that assigns students to teams, using thesample()function with optional argumentreplace=FALSE, to produce a permutation of the upper-case letters using the built-inLETTERSvector.Use the up-arrow on your keyboard to recall the last command calling
sample()and run it again — notice that the output is different.Use the up-arrow twice in your keyboard to recall the set.seed() command you previously run and re-run it.
Now use the up-arrow twice again to rerun the
sample()command and see that you get the same permutation you originally got.Now copy the code that sets the random seed RNG in the first line of the code chunk below, right before the line that reads
answer <- NULL. Then over-writeNULLwith the code that generates the permutation of letters, saving the return value character vector to the nameanswerin the code chunk immediately below.
answer <- NULL
print_and_check(answer,"1bbb353fe30eca7622515f5aa9112163")
## NULL
## [1] "INCORRECT"Selecting Elements from Lists
- In the R Console, use the R named-selection operator (
$) to select just the tenth item (the 10th team as a character vector of UCMNetIDs) from the R objectteamscreated above. Because the name is an integer, you need to enclose it in backquotes like this:
`10`
Once you get this to work, memorialize the correct working code in the right-hand side (RHS) of the assignment to the variable answer and look for CORRECT when you play or render.
answer <- NULL
print_and_check(answer,"c768c11452dfe3da22cd1f90adb4f3f9")
## NULL
## [1] "INCORRECT"