Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
What are vectors?
Vector operations
Indexing and filtering
Summary
27. Vectors - summary

Instruction

Let's briefly summarize what we learned in this part of the course.

R allows us to create vectors, which are data structures representing sequences of elements of the same data type. They can store numbers (numerical vectors), text values (character vectors), or logical TRUE/FALSE values (logical vectors).

We define vectors with either the c() function or the colon ( :) operator.
c(1,2,3,4,5)
1:5

Addition, subtraction, multiplication, and division operations are all defined for vectors and occur in a memberwise fashion. They can occur between two vectors or between a vector and a numerical value.

You can access the elements of a vector using the bracket [] operator. You can access the "i"th element using

a[i]

You can also retrieve several elements at once by listing the index positions:

ages[c(3,5,7)]
ages[1:5]

A third way to access vector elements is to use conditional operators inside the brackets:

ages[ages > 40]

There are many functions that we can use to analyze numerical data, such as min(), max(), mean(), median(), and quantile(). Alternatively, we can use the summary() function to display all this information at once:

summary(ages)

Finally, you can use all functions on vector subsets:

summary(ages[ages >= 18])

Exercise

We learned quite a lot in this part of our course! The six exercises that follow will help test your understanding of the concepts we covered. Click Next exercise to begin!