Question: Suppose 1 , 2 , 3 stands for KFC , Subway and McDonald respectively. Use factor ( ) to turn the numeric vector c (
Suppose stands for KFC Subway and McDonald respectively. Use factor to turn the numeric
vector c into a factor vector named food.
b Now confirm that food is indeed a factor using str which reveals the structure of an R object.
c Now please change the first element in food from to
Hint: food will gives the th element in food.
d Function levels can produce the labels of the factors. Please correct the all the errors in the code
below, which tries to change the labels into McDonald, Subway and KFC
levelfood cKFC Subway, McDonald
e After fixing the codes in the previous subquestion, please use summary or table to check the
frequency of McDonald, KFC and Subway in food.
f Use plot to obtain a bar chart of the variable food. Why do you think the bars are sorted on the
xaxis this way?
g There are many ways to reorder the levels in a factor but here we will focus on the following two
options here.
relevel to specify the reference level, ie the category that is first on the list. This has a
particular implication in a regression setting.
Use the levels argument in factor
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
