Use the built-in dataset state.x77
.
What is the class of the object (use the command class
to find out)? Convert it into a data frame and call it ‘s77’ (find out the command to convert an object into a data frame).
Create a subset of s77
containing the per capita income of the states that have less than 40 days with minimun temperature below freezing point.
Create another subset with the states that have less than 40 days with minimum temperature below freezing point and a life expectancy greater than 71 years.
Order the data frame simultaneously by ‘Illiteracy’ (increasing) and ‘Income’ (decreasing). (This should have been covered in today’s extra R tutorial but you can read up on how to achieve this in the R-ticulate booklet that I have made available on Blackboard)
Read up on the cut
function and add a new ordinal variable to the data frame that divides the ‘Frost’ variable into three categories: ‘low’, ‘intermediate’ and ‘high’ number of frost days.
The cut
function converts a numeric variable into a categorical variable, with multiple levels. We can simply provide the number of intervals desired (break = 3) and R will find cut points (interval boundaries) for us.