Practice: Vectors

This exercise shows how easy it is to work with vectors in R and modify and reorganize the data in vectors. In the exercise, you will create and manipulate a vector, then save elements 5-10 of your vector as a new (separate) vector. This exercise does not count toward your grade. It is just for practice!

Challenge 1

Start by making a vector with the numbers 1 through 26. Multiply the vector by 2, and give the resulting vector names A through Z (hint: there is a built in vector called LETTERS)


Solution to Challenge 1

x <- 1:26
x <- x * 2
names(x) <- LETTERS


Source: The Carpentries, https://swcarpentry.github.io/r-novice-gapminder/04-data-structures-part1/index.html#vectors-and-type-coercion
Creative Commons License This work is licensed under a Creative Commons Attribution 4.0 License.

Last modified: Tuesday, January 3, 2023, 4:26 PM