Introduction to R: Exercises
4. Defining vectors. The c()
function can be used to create vectors in R
. For example, the vector [1, 2, 3, 4, 5]
can be defined with the command c(1,2,3,4,5)
.
Define the following vectors:
- ["one", "two", "three"]
- [TRUE, FALSE, TRUE]
- [1, "two", TRUE]
# Define the vector ["one","two","three"].
char_vector <- c(___,"two",___)
# Define the vector [TRUE,FALSE,TRUE].
logical_vector <- ___(___,___,___)
# Define the vector [1,"two",TRUE].
mixed_vector <- ____
# Define the vector ["one","two","three"].
char_vector <- c("one","two","three")
# Define the vector [TRUE,FALSE,TRUE].
logical_vector <- c(TRUE,FALSE,TRUE)
# Define the vector [1,"two",TRUE].
mixed_vector <- c(1,"two",TRUE)
test_error()
test_object("char_vector", incorrect_msg="Did you define the elements of `char_vector` correctly?")
test_object("logical_vector", incorrect_msg="Did you use the function `c()` to define `logical_vector`?")
test_object("mixed_vector", incorrect_msg="Did you use the function c`()` to define `mixed_vector`?")
success_msg("Excellent work! Notice that `mixed_vector` contains character, logical, and numerical variables.")
Did you use the `c()` function correctly?
Previous Exercise
Next Exercise