R: abc<-c(1:15) vs abcd<-1:15

115 Views Asked by At

What is the difference between the following commands:

abc <- 1:15
abcd <- c(1:15)
abc
abcd

The output is:

> abc <- 1:15
> abcd <- c(1:15)
> abc
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
> abcd
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
1

There are 1 best solutions below

0
On BEST ANSWER

c() is a function to concatenate vectors. In your example you only supply one vector - 1:15 so they are functionally the same.
You need c() if you want to concatenate two or more ranges, for example to not have 13 in your vector: c(1:12, 14:15)