Social Media Research

02 R Data Analysis


Question

list1<-list(1,"a", TRUE, c(2.2, 5.1))

  1. Return the 4th element of list1.
  2. Return the second value of the 4th element of list1.

Answer
  1. list1[[4]]
  2. list1[[4]][2]

Lists can be indexed in two ways:

  • [i] returns a list of elements. i can be an integer or a vector [i:j], just like when indexing a vector
  • [[i]] returns a single element. i can only be a single value



Comments