The c() function in R is “used to combine or concatenate its argument”. The c() stands for “combine”. It returns the output by giving parameters inside the function.
Syntax
c(…, recursive = FALSE, use.names = TRUE)
Parameters
- …: They are the objects to be concatenated.
- recursive: It is logical. If recursive = TRUE, the function recursively descends through lists (and pairlists), combining all their elements into a vector.
- use.names: It is a logical argument indicating if names should be preserved.
Return Value
The c() function returns NULL, an expression, or a vector of an appropriate mode.
Example 1: Simple use of the c() function
In R, the c() function returns a vector.
rv <- c(19, 21)
rv
rv[1]
rv[2]
Output
[1] 19 21
[1] 19
[1] 21
If you want to create a vector with 11 entries, use the following function.
data <- (1:11)
print(data)
Output
[1] 1 2 3 4 5 6 7 8 9 10 11
Example 2: Concatenate two vectors using the c() function
To concatenate two vectors in R, you can use the c() function.
p <- c(1, 1)
p <- c(1, 5)
p <- c(p, c(1, 1.5))
p <- c(p, p)
print(p)
Output
[1] 1.0 5.0 1.0 1.5 1.0 5.0 1.0 1.5
That is it for the c() function in R.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.