R Assignment Challenge 2

In this second practice, we will cover the concepts from the below topics

  1. R Tutorial 6: Data Manipulation
  2. R Tutorial 7: Data Manipulation (Continued)
  3. R Tutorial 8: Data Visualisation

Exercise 1 – Data Manipulation

In this practice, you will have to load the data Boston in the library MASS and answer the following questions about the data set.

These are the meaning of the column names for the Boston dataset:

  1. crim – per capita crime rate by town.
  2. zn – proportion of residential land zoned for lots over 25,000 sq.ft.
  3. indus – proportion of non-retail business acres per town.
  4. chas – Charles River dummy variable (= 1 if tract bounds river; 0 otherwise).
  5. nox – nitrogen oxides concentration (parts per 10 million).
  6. rm – average number of rooms per dwelling.
  7. age – proportion of owner-occupied units built prior to 1940.
  8. dis – weighted mean of distances to five Boston employment centres.
  9. rad – index of accessibility to radial highways.
  10. tax – full-value property-tax rate per \$10,000.
  11. ptratio – pupil-teacher ratio by town.
  12. black – 1000(Bk – 0.63)^2 where Bk is the proportion of blacks by town.
  13. lstat – lower status of the population (percent).
  14. medv – median value of owner-occupied homes in thousands


  1. Boston is a data frame, what is the dimension of this data frame?
  2. What’s the average value of data in this age column?
  3. Find all entries of age that are more than the mean value of the data in the age vector.
  4. The 10th to the 85th observations (row) are recorded wrongly so they are to be excluded from the dataset, so what’s the new mean value of the data in the age column
  5. If now 85th to 100th observations are recorded wrongly, what is the median value in the age column?
  6. What’s the minimal value of all data in the age column, and which row is it?
  7. The column name chas is a factor variable, which means if the entry is 1 the data tract bounds the river, 0 otherwise. We also will are concerned about the crime rate in the region, so we will be looking at the column crim as well. Isolate observations that at least one of the following is satisfied (you need to use alot of “and” and “or”)
    1. The data tract bounds river, and crime rate is less than average crime rate of all data.
    2. The data does not tract bounds river, and crime rate is less than median crime rate of all data.
    3. The crime rate is extremely low, i.e. lower than the first quantile of all data. You many use quantile function to help you.
  8. What is the average value of medv of all these observations that fulfills at least 1 of the 3 observation.

Assignment requirements

For each question 1 to 7, process the data and store the answer into variable named “Q1” to “Q7” accordingly.


Exercise 2 – Data Visualisation

This will be a simple graph, but plot a scatter plot of prices (medv) against the crime rate in the region (crim) to observe the relationship between the two variables.

Scatterplots are not in the tutorial, so this is a test of your skills in googling solution. (hint: look for cheatsheets for ggplot2)

Assignment requirements

Just make sure the line of code to create the visualisation works.

– End of Assignment 2 –

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s