Creating a vector and accessing its properties
In this recipe, you will learn what a vector is in R, and how to create it, access its properties, and perform certain operations.
Getting ready
To follow this recipe, you need the R software installed on your computer. Before going to the next step, you have to understand the definition of a vector in R. In R, a vector is simply a collection of values with the same type; it could be all character
, numeric
, or logical
. For example, it could contain names of places/countries, it could contain the number of hours a person spends on the internet over the last seven days, or it could also contain whether a group of people has a certain disease or not (true/false).
How to do it…
Creating a vector in R is the most easy task.
Take a look at the following steps to learn how to create a vector in R:
- There are several ways in which you can create a vector, but the most popular and easy way to create the vector is using the concatenate function
c()
as shown...