c()
get_help() docs
The c() function comes with R and is part of the Base R {base} package.
We use this function to create arrays. Recall that all values in arrays must have the same type.
If you are using colon syntax to create an array (e.g. 1:5 to create an array with values 1,2,3,4,5, you do not need to use c().
c(first value in array, second value in array, etc.)# Define an array with all numeric values as shown, and reveal output
new_array <- c(8, 5, 3, 6, 1, 2, 7, 88)
new_array## [1] 8 5 3 6 1 2 7 88
# Define an array with all character values as shown, and reveal output
new_array <- c('a', 'e', 'i', 'o', 'u', 'y')
new_array## [1] "a" "e" "i" "o" "u" "y"
# Defining an array with both numeric and character values will turn
# all values into characters
new_array <- c('a', 'e', 'i', 'o', 'u', 'y', 1, 2, 3, 4, 5)
new_array## [1] "a" "e" "i" "o" "u" "y" "1" "2" "3" "4" "5"
# To create an array of ordered numbers, you can use `:` without `c()`
ordered_numbers <- 5:20
ordered_numbers## [1] 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20