01 · Basics and Vectors
- <-
- c()
- vector
- logical
- character
- numeric
- matrix
End of the R Course
Congratulations: you have successfully completed the 3 modules of the R Course — from vector manipulation to data frame exploration, up to writing reusable functions and performing basic statistical analysis. Now, take on the final challenge to consolidate your learning!
Reminder: R exercises are verified statically (keywords). To actually run the code, each exercise provides a OneCompiler button that copies the code and opens the sandbox.
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 experiment freely, or use OneCompiler to run complex scripts.