Examining Variables
In this module we have learned that every variable has a class. For example, the class can be a character, numeric or logical. The function class()
can be used to determine the class of an object.
Here we are going to determine the class of one of the variables in the murders
data frame. To extract variables from a data frame we use $
, referred to as the accessor.
In the editor we show an example of how to do this. Let`s try it out for ourselves.
This exercise is part of the course
Data Science R Basics
Exercise instructions
Use the accessor $
to extract the state abbreviations and assign them to the object a
.
What is the class of this object?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# To access the population variable from the murders dataset use this code:
p <- murders$population
# To determine the class of object `p` we use this code:
class(p)
# Use the accessor to extract state abbreviations and assign it to a
# Determine the class of a