Quantcast
Channel: r software hub
Viewing all articles
Browse latest Browse all 1015

A Tall Drink of Water

$
0
0

By Julia Silge

Annual Water Use in SLC

In a previous post, I used water consumption data from Utah’s Open Data Catalog to explore what kind of users consume the most water in my home here in Salt Lake City, what the annual pattern of water use is, and how the drought of the past few years has affected water use. I made a predictive model for the total aggregate water use of the city and tested how drought affected the accuracy of such a model. The data set I used for all of this also contains spatial information that I basically ignored in that first post; today let’s dig in to the spatial information and map water use in my fair city!

Salt Lake City makes water consumption data publicly available at both the census tract and block level; I am going to use the census tract level information here today. The data set includes information on the type of water user (single residence, apartment, hospital, business, etc.) and amount of water used from 2000 into 2015. The data at the census tract level is available here via Utah’s Open Data Catalog and can be accessed via Socrata Open Data API.

library(RSocrata)
water  read.socrata("https://opendata.utah.gov/resource/j4aa-ce7s.csv")

After loading the data, we need to do the same cleaning up as last time. There is one nonsensical row that needs removing with a non-year value in the year column. Then, let’s adjust the data types.

water  water[grep("[0-9]{4}", water$YEAR),]
water[,1:4]  lapply(water[,1:4], as.factor)
water[,5:6]  lapply(water[,5:6], as.numeric)

Now let’s use dplyr to group these observations of water use by each tract and month. I use the median for the consumption because it is less sensitive to outliers than the mean; if you remember from the last post, there are some very high outliers in water use during the drought years and my main goal …read more

Source:: r-bloggers.com


Viewing all articles
Browse latest Browse all 1015

Trending Articles