Goal: Practice working with string data and regular expressions.
Use the dinesafe data for all questions.
library(tidyverse)
dinesafe = read_csv("../data/dinesafe.csv")
Find all distinct establishments that contain the word “kebab” or its variations “kabob”, “kabab”, “kebob” in their name. Use a single regular expression for all variations, and consider both cases (upper & lower).
Find all distinct establishments that contain the exact word “pho” in their name (in either case). Ensure your regular expression excludes words that just contain the string “pho”, such as “chophouse”.
Some of the INFRACTION_DETAILS
entries contain a reference to the relevant regulation that was broken. It typically appears at the end of the string and looks like this “o. reg 562/90 sec. 74(c)”. This refers to Ontario Regulation 562/1990 revision, section 74(c), which you can view at https://www.ontario.ca/laws/regulation/900562.
Find what proportion of infraction details contain a reference to Ontario Regulation 562/90. You will have to formulate a regular expression that detects the presence of such a reference.
Extract the relevant section number for all infractions that refer to Ontario regulation 562/90. Use this information to create a frequency barplot of the number of infractions by section.
For each distinct ESTABLISHMENT_ID
, combine all non-NA INFRACTION_DETAILS
into a single string. Then count the number of times the word “contamination” appears in each establishment’s combined infraction details. Create a barplot of the top-10 contamination offenders (i.e. establishment name vs number of occurances of word “contamination”).
LS0tDQp0aXRsZTogIlNUQUE1NyAtIFdvcmtTaGVldCA3Ig0KYXV0aG9yOiAnTmFtZTogICAgLCBJRCM6ICAgJw0Kb3V0cHV0OiBodG1sX25vdGVib29rDQotLS0NCg0KYGBge3Igc2V0dXAsIGluY2x1ZGU9RkFMU0V9DQpsaWJyYXJ5KHRpZHl2ZXJzZSkNCmxpYnJhcnkoZ2FwbWluZGVyKQ0KYGBgDQoNCioqR29hbCoqOiBQcmFjdGljZSB3b3JraW5nIHdpdGggc3RyaW5nIGRhdGEgYW5kIHJlZ3VsYXIgZXhwcmVzc2lvbnMuDQoNCg0KVXNlIHRoZSAqZGluZXNhZmUqIGRhdGEgZm9yIGFsbCBxdWVzdGlvbnMuIA0KYGBge3J9DQpsaWJyYXJ5KHRpZHl2ZXJzZSkNCmRpbmVzYWZlID0gcmVhZF9jc3YoIi4uL2RhdGEvZGluZXNhZmUuY3N2I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