c
is not the abbreviation of vector in English, so why use c()
to define a vector in R?
v1<- c(1,2,3,4,5)
c is not the abbreviation of vector in English, so why use c() to define a vector in R? ? c states it stands for combine. The help file shows that can also be used for combining lists.
c() function in R Language is used to combine the arguments passed to it.
A vector is a basic data structure which plays an important role in R programming. In R, a sequence of elements which share the same data type is known as vector. A vector supports logical, integer, double, character, complex, or raw data type.
This is a good question, and the answer is kind of odd. "c", believe it or not, stands for "combine", which is what it normally does:
> c(c(1, 2), c(3)) [1] 1 2 3
But it happens that in R, a number is just a vector of length 1:
> 1 [1] 1
So, when you use c()
to create a vector, what you are actually doing is combining together a series of 1-length vectors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With