Numeric Vectors
A vector is a series of values, all of the same type. They are the most basic data type in R and can hold numeric data, character data, or logical data. In R, you can create a vector with the concatenate (or combine) function c()
. You place the vector elements separated by a comma between the parentheses. For example a numeric vector would look something like this:
cost <- c(50, 75, 90, 100, 150)
This exercise is part of the course
Data Science R Basics
Exercise instructions
Use the function c()
to create a numeric vector with the average high temperatures in January for Beijing, Lagos, Paris, Rio de Janeiro, San Juan, and Toronto.
The average high temperatures are 35, 88, 42, 84, 81, and 30
degrees Fahrenheit. Call the object temp
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Here is an example creating a numeric vector named cost
cost <- c(50, 75, 90, 100, 150)
# Create a numeric vector to store the temperatures listed in the instructions into a vector named temp
# Make sure to follow the same order in the instructions