title: “Activity 3 - R Data Structures” output: html_notebook —

Vectors

x <- c(10, 20, 30, 40, 50) x

length(x)

Factors

colors <- factor(c(“red”, “blue”, “red”, “green”)) colors

levels(colors)

Lists

my_list <- list( name = “Joao”, age = 25, scores = c(90, 85, 88) )

my_list my_list\(name my_list\)scores

Matrices

m <- matrix(1:6, nrow = 2, ncol = 3) m

Data Frames

df <- data.frame( Name = c(“Ana”, “Bob”, “Carlos”), Age = c(22, 25, 30), Grade = c(90, 85, 88) )

df

Indexing

df$Name df[1, ] df[, 2]

Final Comments

This activity helped me understand the main data structures in R, including vectors, factors, lists, matrices, and data frames. Running the examples made it easier to see how data is organized and accessed in R, which is essential for data analysis.