Get Started

c()ombine

Now is where things get fun! It is time to create your first vector. Since this is a finance oriented course, it is only appropriate that your first vector be a numeric vector of stock prices. Remember, you create a vector using the combine function, c(), and each element you add is separated by a comma.

For example, this is a vector of Apple's stock prices from December, 2016:

apple_stock <- c(109.49, 109.90, 109.11, 109.95, 111.03, 112.12)

And this is a character vector of bond credit ratings:

credit_rating <- c("AAA", "AA", "BBB", "BB", "B")

This is a part of the course

“Introduction to R for Finance”

View Course

Exercise instructions

  • Another example of a numeric vector for IBM stock prices is shown for you.
  • Create a character vector of the finance related words "stocks", "bonds", and "investments", in that order.
  • Create a logical vector of TRUE, FALSE, TRUE in that order.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Another numeric vector
ibm_stock <- c(159.82, 160.02, 159.84)

# Another character vector
finance <-

# A logical vector
logic <- 
Edit and Run Code