O'Reilly logo

Data Manipulation with R by Jaynal Abedin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Vector

The R vector can be contiguous cells containing data. In R, the basic data storage type is vector. The vector itself could be numeric, character, and logical based on the elements. In fact, there are six types of vectors used in R. We can easily access elements of a vector through indexing. The following example shows how we can create a vector and access its individual elements and group of elements:

# creating a vector and accessing elements vector1 <- c(1,3,5,7,9) vector1 [1] 1 3 5 7 9 # accessing second elements of "vector1" vector1[2] [1] 3 # accessing three elements starting from second element vector1[2:4] [1] 3 5 7 # another way of creating vector. Here "from" is the starting point # of the vector and "to" is the end point of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required