Data Stucture: Vector
1. Creating Vectors
2. Basic Arithmetic on Vectors:
3. Accessing Elements:
Given the vector months <- c("Jan", "Feb", "Mar", "Apr", "May")
, retrieve the third element. Try accessing multiple elements by extracting the first, third, and fifth elements.
4. Vector Length:
5. Logical Indexing:
6. Combining Vectors:
7. Sorting Vectors:
8. Applying Functions:
9. Removing Elements:
10. Vector Recycling:
Use the vector x <- c(2, 4, 6)
and another vector y <- c(1, 2)
. Add x
and y
together to see how R handles vector recycling. Explain the result.