Session Ready
Exercise

Compute tree density by neighborhood (I)

In order to compute tree density by neighborhood you need two things. You will need to know the area of the neighborhoods, which you will compute in the next exercise. And you need the tree counts by neighborhood which is the focus of this exercise.

You will produce counts of all trees by neighborhood in NYC and create a single data frame with a column for total trees. The result should be a data frame with no geometry.

Instructions
100 XP

sf and dplyr are loaded in the workspace.

  • Use the count() function from dplyr on the trees object to compute total trees by neighborhood. The neighborhood variable is hood. Call the new object tree_counts.
  • Use head() to take a quick look at tree_counts and see if the geometry variable still exists.
  • Remove the geometry from your tree_counts data frame.
  • The default for the count() function is to name the count field n. Use the rename() function from dplyr to change the column called n to tree_cnt.
  • Use hist() to create a quick histogram of the tree counts.