Exercises – Basics (Introduction to R)

Author
Affiliation

Jürgen Wilbert

University of Münster

Published

October 30, 2025

Basic concepts

  1. Create a numeric vector x with five values and compute its mean and standard deviation using base R.
  2. Create a character vector id and a logical vector passed each of four elements. Combine them into a data.frame and inspect with str().
  3. Use names() to assign column names to a data frame you created and verify with names(dat).
  4. Create a q_1, q_2, q_3 up to q_25 two times with paste() and with paste0().
  5. Compute the square root of 2, the exponential of 1, and the natural logarithm of 10.
  6. Create a list with three heterogeneous elements (numeric, character, logical). Access elements by name and by position.
  7. Use factor() to create a factor with levels A and B. Show the internal integer representation with as.numeric().
  8. Add comment lines to three of the previous tasks. Use # for each line.
  9. Add three section headers to your R script using # ---- separators that help to organise your text.
  10. Open the help page for rank with ?rank and summarize what it does.