Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use c() to define vector?

Tags:

r

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) 
like image 272
Peng Peng Avatar asked Jul 15 '12 02:07

Peng Peng


People also ask

Why is c used in vector R?

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.

What is the use of c () in R?

c() function in R Language is used to combine the arguments passed to it.

Why do we use vectors in R?

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.


1 Answers

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.

like image 58
Owen Avatar answered Sep 22 '22 17:09

Owen