Select Page

STAT 184 Penn State University REGEX Problem Public Safety Data Online Questions

Question Description

I’m working on a r question and need a sample draft to help me study.

REGEX Problem 17.8 from https://dtkaplan.github.io/DataComputingEbook/chap…

Problem 17.8: The city of Boston publishes various public-safety data online. A data table listing almost 300,000 crime reports from Feb. 6, 2012 up through the present is available via https://data.cityofboston.gov/Public-Safety/Crime-Incident-Reports/7cdf-6fgx

A small, convenient extract of the Boston crime data is available to you:

CrimeSample <- readr::read_csv("http://tiny.cc/dcf/Boston-Crimes-50.csv")

The Location variable contains information about latitude and longitude. Each of these is a number, but they are represented in Location as a formatted character string.

Write a regular expression that will extract the latitude and longitude as numbers into separate variables. To do the extraction you can use tidyr::extract(), e.g.

my_regex <- # Your regular expression goes hereCrimeSample %>%tidyr::extract("Location", into=c("lat", "long"),                  regex = my_regex,                  convert = TRUE)

Some hints:

  • You’ll need the extraction parentheses, written as plain parens: ( ). If you want to refer to the parentheses characters, not as extraction markers but as plain text, you need to “escape” them with backslashes, e.g. "\(some pattern in parens\)" The two backslashes are needed so that R realizes that you are escaping the character that follows.
  • The regex symbol for a digit is [0-9].
  • A regex that will extract a single floating-point number surrounded by parentheses is: "\([+-]*[0-9]*[0-9\.][0-9]*\)"

I need the answer in R code, thanks in advance.

"Place your order now for a similar assignment and have exceptional work written by our team of experts, guaranteeing you "A" results."

Order Solution Now