Session Ready
Exercise

Vector names()

Let's return to the example about January and February's returns. As a refresher, in January you earned a 5% return, and in February, an extra 2% return. Being the savvy data scientist you are, you realize that you can put these returns into a vector! That would look something like this:

ret <- c(5, 2)

This is great! Now all of the returns are in one place. However, you could go one step further by adding names to each return in your vector. You do this using names(). Check this out:

names(ret) <- c("Jan", "Feb")

Printing ret now returns:

Jan Feb 
5   2

Pretty cool, right?

Instructions
100 XP
  • Defined for you are a vector of 12 monthly returns, and a vector of month names.
  • Add months as names to ret to create a more descriptive vector.
  • Print out ret to see the newly named vector!