← All languages
R function of the day
Random

c

Combine values into a vector or list.

Description

The c() function combines its arguments to form a vector. All arguments are coerced to a common type which is the type of the returned value. If the arguments are of mixed types, coercion follows the hierarchy NULL < raw < logical < integer < double < complex < character < list < expression.

c() is the most fundamental function in R for creating vectors, which are the basic data structure. It is recursive: if any arguments are themselves vectors, their elements are concatenated into the result.

Arguments

NameDescriptionOptional
... Objects to be concatenated. Can be any number of values, vectors, or lists. No
recursive If TRUE and arguments contain lists, the function descends into lists combining all elements. Yes

Example

c(1, 2, 3)           # 1 2 3
c("a", "b", "c")     # "a" "b" "c"
c(TRUE, FALSE, TRUE)  # TRUE FALSE TRUE
c(1, "a")             # "1" "a" (coerced to character)

Reference