Create a R script file, write code for following questions.
Use the murders dataset to answer the following questions.
Generate a new column named as populationinmillions, which is
population
Create a murder rate with murders mutatemurders rate total
population
If rankx gives you the ranks of x from lowest to highest, rankx gives you
the ranks from highest to lowest. Use the function mutate to add a
column rank containing the rank, from highest to lowest murder rate.
Show the murder data for New York state.
See data from both New York and Texas.
Create a new data frame called noflorida with data except that of
Florida state.
Create a new data frame called murdersnw with only the states
from the Northeast and the West.
Suppose you want to live in the Northeast or West and want the
murder rate to be less than We want to see the data for the states
satisfying these options. Note that you can use logical operators
with filter. Here is an example in which we filter to keep only small
states in the Northeast region.
filtermurders population & region "Northeast"
Make sure murders has been defined with rate and rank and still has all
states. Create a table called mystates that contains rows for states
satisfying both the conditions: it is in the Northeast or West and the
murder rate is less than Use select to show only the state name, the
rate, and the rank.
Reset murders to the original table by using datamurders Use a pipe to
create a new data frame called mystates that considers only states in the
Northeast or West which have a murder rate lower than and contains
only the state, rate and rank columns. The pipe should also have four
components separated by three The code should look something like
this:
mystates murders
mutate SOMETHING
filter SOMETHING
select SOMETHING