01 · Bases and Vectors
- <-
- c()
- recycling
- coercion
- logical
- numeric
- matrix
End of the R Course
Congratulations: you have completed all 8 modules of the R Course — from atomic vectors and data frames to tidyverse, ggplot2, inferential statistics, lm() linear regression, and data pipelines. Take on the final challenge!
Exercises execute live in your browser using WebR (WebAssembly) alongside keyword and output verification; you can also test freely inside the R Playground.
Complete the R code snippets to create a data frame, iterate over data with a for loop, and implement a function for calculating the statistical mean.
Create a data frame named store_data with two columns: products and sales. Module 2 (Data Frames).
Define a data frame named store_data with a column products containing character values "A", "B", "C" and a column sales with numeric values 100, 250, 150.
Use the syntax: store_data <- data.frame(products = c("A", "B", "C"), sales = c(100, 250, 150))
Solution available after 3 attempts
Run a loop to print numbers from 1 to 5. Module 2 (Conditionals and Loops).
Write a for loop that iterates over the sequence 1 to 5 using the variable num and prints each value with print(num).
Use the syntax: for (num in 1:5) { print(num) }
Solution available after 3 attempts
Define a custom function that computes the mean. Module 3 (Writing Functions).
Define the function analyze_vector that accepts an argument v and returns the mean of the elements computed via mean(v).
Use: analyze_vector <- function(v) { return(mean(v)) }
Solution available after 3 attempts
A single page with all the essential syntax of R, ready to keep handy while you code.
Consistent practice is key. Open the R Playground to run scripts live in WebR or experiment freely.