Task:
Create variables a = 10, b = 20; compute
c = a*b and print the result using: 1) direct printing
(typing the variable name), and
2) print().
# TODO: Write your code here
a <- 10
b <- 20
c <- a * b
# 1) direct printing
c
#> [1] 200
# 2) using print()
print(c)
#> [1] 200
Task:
1) Create a numeric vector of grades (at least 6
values).
2) Create a mixed vector of student names and ages
(example: “Ali”, 20, “Sara”, 21).
3) Show class() for both vectors.
4) Compute ONE basic statistic for grades (choose one:
mean(), median(), sd(),
min(), max()).
# TODO: Write your code here
# 1) numeric vector of grades (6+ values)
grades <- c(88, 92, 76, 85, 90, 81)
# 2) mixed vector of names and ages
mixed <- c("Ali", 20, "Sara", 21, "Drake", 22)
# 3) show class() for both
class(grades)
#> [1] "numeric"
class(mixed)
#> [1] "character"
# 4) one basic statistic for grades (example: mean)
mean(grades)
#> [1] 85.33333
Brief interpretation (1–2 sentences):
- What did you notice about the class of the mixed vector?
Task:
Make two 2×3 matrices using the numbers 1,2,3,4,5,6: 1)
filled row-wise, and
2) filled column-wise.
Print both matrices.
# TODO: Write your code here
# 1) row-wise fill
mat_row <- matrix(1:6, nrow = 2, ncol = 3, byrow = TRUE)
# 2) column-wise fill (default)
mat_col <- matrix(1:6, nrow = 2, ncol = 3, byrow = FALSE)
# print both
mat_row
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 4 5 6
mat_col
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 2 4 6
Task:
Build a small data frame for 5 students with columns: -
Name - Age - Course -
Grade
Then: 1) print the data frame
2) show its structure using str()
3) show summary statistics using summary()
# TODO: Write your code here
students <- data.frame(
Name = c("Drake", "Ali", "Sara", "Mia", "Noah"),
Age = c(22, 20, 21, 19, 23),
Course = c("CE 372", "CE 372", "CE 372", "CE 372", "CE 372"),
Grade = c(93, 85, 90, 78, 88)
)
# 1) print
students
# 2) structure
str(students)
#> 'data.frame': 5 obs. of 4 variables:
#> $ Name : chr "Drake" "Ali" "Sara" "Mia" ...
#> $ Age : num 22 20 21 19 23
#> $ Course: chr "CE 372" "CE 372" "CE 372" "CE 372" ...
#> $ Grade : num 93 85 90 78 88
# 3) summary statistics
summary(students)
#> Name Age Course Grade
#> Length:5 Min. :19 Length:5 Min. :78.0
#> Class :character 1st Qu.:20 Class :character 1st Qu.:85.0
#> Mode :character Median :21 Mode :character Median :88.0
#> Mean :21 Mean :86.8
#> 3rd Qu.:22 3rd Qu.:90.0
#> Max. :23 Max. :93.0
Task:
Read a CSV file using a text connection (NOT
read.csv("file.csv") directly).
Then show: 1) tail() tail(df) 2) summary()
summary(df)
Option A (recommended): Use the provided CSV
file
- Put the file (example: CE 372_dataset1.csv) in the same
folder as this .Rmd.