# create a character vector
my_vector <- c("apple", "banana", "cherry")
print(my_vector)
## [1] "apple" "banana" "cherry"
# access the first element of the vector
print(my_vector[1])
## [1] "apple"
# create a character matrix
my_matrix <- matrix(c("dog", "cat", "bird", "fish"),
nrow = 2)
print(my_matrix)
## [,1] [,2]
## [1,] "dog" "bird"
## [2,] "cat" "fish"
# access the second element of the first row
print(my_matrix[1, 2])
## [1] "bird"
my_array <- array(c("red", "blue", "green", "yellow"),
dim = c(2, 2, 2))
print(my_array)
## , , 1
##
## [,1] [,2]
## [1,] "red" "green"
## [2,] "blue" "yellow"
##
## , , 2
##
## [,1] [,2]
## [1,] "red" "green"
## [2,] "blue" "yellow"
print(my_array[,,2][4])
## [1] "yellow"
my_df <- data.frame(fruit = c("apple", "banana", "cherry"),
color = c("red", "yellow", "red"))
print(my_df)
## fruit color
## 1 apple red
## 2 banana yellow
## 3 cherry red
print(my_df[2, "color"])
## [1] "yellow"
my_list <- list("apple", "banana", "cherry")
print(my_list)
## [[1]]
## [1] "apple"
##
## [[2]]
## [1] "banana"
##
## [[3]]
## [1] "cherry"
print(my_list[[3]])
## [1] "cherry"