R self-assessment test and further pointers.

This is a short self-assessment test* for participants who are unsure if they have enough experience with R. If you are able to solve the exercises below (also with the help of Google and Stackoverflow), you have enough experience with R for the course. If not, below the exercises you will find links to some R crash courses that you have to go through on your own (you don’t have to go through all of them, choose the one(s) you like the best) before you take our course.

Using function rep() create a numerical vector with 24 elements that repeats the following sequence 4 times `c(1, 2, 3, 4, 5, 6)`

.

Create a dataframe named `df_cake`

with twenty rows and four columns: `Person, Age, Cake, Coffee`

. Populate column `Person`

with twenty names of your choice. Populate column `Age`

with ten random numbers between 18 and 80. Column `Cake`

should be populated with cake names from the following vector in random order `c("Tiramisu", "Lemon Tart", "Brownie", "Cheesecake", "Carrot Cake")`

. Column `Coffee`

should be randomly populated with 0 and 1, where 0 means that the person did not have coffee with their cake, and 1 that they had coffee with their cake.

*Now answer the following questions about the resulting dataframe:*

- What is the mean age of the people in the dataframe? How about the median?
- What is the most popular cake?
- What is the most popular cake among the people that had coffee with their cakes?
- What is the mean and median age of the people who did not have coffee with their cakes?

Write a function called `blueberry`

that would replace all the values equal to `Carrot Cake`

in a dataframe with `Blueberry Cake`

. Now apply this function to your `df_cake`

dataframe.

Add a column `Age Group`

to your `df_cake`

dataframe. Assign value `Youth`

to `Age Group`

for people whose Age is between 18 and 25. If a person’s Age is between 25 and 65, set their `Age Group`

to `Adult`

. If their Age is over 65, set their `Age Group`

to `Senior`

.

Links to R crash courses:

- Crash Course in R by David Garcia (additional materials are available here
- R tutorial by Kelly Black - only chapters 1,2,3,7,13 https://www.cyclismo.org/tutorial/R/index.html
- R crash course by Bill Petti https://billpetti.github.io/Crash_course_in_R/
- R crash course from FU Berlin https://blogs.fu-berlin.de/reseda/r-crash-course-6/

*This test is adapted from a test developed by Ueli Reber, Thomas Hauessler and Aleksandra Urman for students of the University of Bern in Fall 2020.