Indexing Method to Indicate Variables
Learn about the indexing method to indicate the variables.
We'll cover the following
Could we use the indexing method to indicate variables?
We can use the indexing numbers to refer to variables in a dataset. To do so, we first use the names()
function to find the indexing numbers for relevant variables, and then we can refer to them in other functions. The following is an example of how to choose country
, year
, and rgdpl
from the pwt7
dataset.
Note that based on the output for
names()
function, the number inside the brackets is the indexing number for the variable right next to it.
In this case below, country
is in the first column, year
in the third column, and rgdpl
in the 24th column. So the two lines of code produce the same output.
Get hands-on with 1400+ tech skills courses.