version
Objective
To familiarize students with the R programming environment, basic commands, and fundamental concepts such as packages, help pages, R objects, and notation.
Submission
Download the Module 1 exercise R scipt
Save your completed R script as:
module1_lab_lastname_firstname.R- Ensure your Answer Sheet (reflection and written responses) is filled out completely.
Check your work
- Verify that all code runs without errors.
- Make sure your name, student ID, and course/year are included in the answer sheet.
Upload to Google Form
- Upload your R script
module1_lab_lastname_firstname.Rusing this Submission link. - Fill in the required student information fields (Name, Student ID, Course/Year).
- Submit before the deadline
- Upload your R script
Part A: Setting up R and RStudio
- Install R and RStudio
- Download and install R from CRAN.
- Download and install RStudio Desktop.
- Download and install R from CRAN.
- Check version
Part B: Packages and Help Pages
Install and load a package.
Install the tidyverse package:
install.packages("tidyverse")
library(tidyverse)- Verify that the package loaded successfully.
- Explore help pages
- Use the help function to learn about mean():
?mean
help(mean)- Summarize what the function does and the arguments it accepts.
Part C: R Objects
Create basic objects
Create a numeric vector
x <- c(2, 4, 6, 8, 10)- Create a character vector:
names <- c("Anna", "Ben", "Carla")- Create a data frame:
df <- data.frame(ID = 1:3, Name = names, Score = c(85, 90, 88))- Inspect objects
- Use functions like class(), length(), str(), and summary() to explore the objects.
Part D: R Notation
Indexing and subsetting
- Extract the 3rd element of vector x.
- Extract the Score column from df.
- Extract the second row of df.
Applying functions
- Compute the mean of vector x.
- Compute the mean of the Score column in df.