#ch2_1 Creata a vector c()
c("hearts", "spades", "diamonds", "diamonds", "spades")
drawn_suits <- c("hearts", "spades", "diamonds","diamonds", "spades")
drawn_suits
is.vector(drawn_suits)
remain <- c(11, 12, 11, 13)
remain
suits <- c("spades", "hearts", "diamonds", "clubs")
#Name a vector
names(remain) <- suits
remain
remain <- c(spades = 11, hearts = 12, diamonds = 11, clubs = 13)
remain
remain <- c("spades" = 11, "hearts" = 12, "diamonds" = 11, "clubs" = 13)
remain
#There are 3 options in naming a vector
#option 1 create both vectors and assign using names() function
remain <- c(11, 12, 11, 13)
suits <- c("spades", "hearts", "diamonds", "clubs")
names(remain) <- suits
#option 2 assign name directly during vector creation
remain <- c(spades = 11, hearts = 12, diamonds = 11, clubs = 13)
#option 3 same as option 2 but using "" in names vector
remain <- c("spades" = 11, "hearts" = 12, "diamonds" = 11, "clubs" = 13)
str(remain)
#single value=vector
my_apples <- 5
my_oranges <- "six"
is.vector(my_apples)
is.vector(my_oranges)
length(my_apples)
length(my_oranges)
length(drawn_suits)
#length of a vector is number of elements in a vector
#Vectors are homogeneous
# Only elements of the same type
# Atomic vectors <> lists
# Automatic coercion if necessary (converting data type)
#Coercion for vectors
drawn_ranks <- c(7, 4, "A", 10, "K", 3, 2, "Q")
drawn_ranks
class(drawn_ranks)
#class is a function to display type of a vector
#Continue with Practice