September 2018
Beginner
206 pages
4h 27m
English
Herein, we will create factor variables in a dataset both one at a time and by using a method that converts multiple variables at once. In order to do so, the following steps have to be executed:
Load the dplyr library. Use levels() to see how many levels of band_instruments$plays exist, as follows:
levels(band_instruments$plays)
Create a new variable, plays2, using ifelse() to change the levels bass and guitar to 1 and 2 using the following code:
band_instruments$plays2 <- ifelse(band_instruments$plays == "bass", 1,ifelse(band_instruments$plays == "guitar", 2, band_instruments$plays))
Use levels() to see how many levels of midwest$state exist as follows:
levels(midwest$state) ...
Read now
Unlock full access