November 2017
Beginner to intermediate
204 pages
5h 23m
English
Vectors in R are analogous to Python lists - they are a data structure that contains an ordered list of values. A vector can be created using the following syntax:
vector <- c(<element1>, <element2>, <element3>)
Try entering the following in your R console:
> c(1,2,3,4,5,6)
It is also possible to create a vector consisting of a sequence of numbers using the following syntax:
sequence_of_numbers <- <start_number>:<finish_number>
Try entering the following into your R console:
> 1:5
Vectors can be indexed using integer numbers or other vectors. For example, the following creates a vector called my.vector, prints the third value of my.vector, and then prints the first five values of my.vector:
my.vector=1:10print(my.vector)print(my.vector[3]) ...
Read now
Unlock full access