1

I'm using this LA area crime dataset in R. http://catalog.data.gov/dataset/crimes-2012-2015/resource/a2369c45-fcdb-4819-b3fc-979c7b737aed I'm trying to separate the crime "Burglary" from the rest of the crimes in the column named CrmCd.Desc. Here is my code so far:

crime_data <- read.csv('/Users/my_user_name/Downloads/Crimes_2012-2015.csv')
View(crime_data)
crime_data$CrmCd.Desc

I tried this:

burg <- crime_data$CrmCd.Desc['Burglary']

And it showed me this which is not what I'm looking for.

[1] <NA>
158 Levels:  ABORTION/ILLEGAL ARSON ... WEAPONS POSSESSION/BOMBING

This shows the entire column of CrmCd.Desc. How do I just show the rows that contain "Burglary" within this column? Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tomas
  • 115
  • 1
  • 2
  • 12
  • Just updated what I tried – Tomas Jul 01 '16 at 00:03
  • [This is the first dupe I found](http://stackoverflow.com/q/27709404/903061), seems to match pretty well. [This is an R-FAQ](http://stackoverflow.com/q/7106330/903061), but seems like a less good match. – Gregor Thomas Jul 01 '16 at 00:06
  • use `crime_data <- read.csv('/Users/my_user_name/Downloads/Crimes_2012-2015.csv', as.is=TRUE)` This way, you won't have to deal with factor variables and can work with character variables, which are much nicer. – lmo Jul 01 '16 at 00:14
  • 1
    You will need to do a little research on subsetting. See `?subset`. This will give you a start: `burg <- crime_data[ crime_data$CrmCd.Desc == 'Burglary', ]`. – Dave2e Jul 01 '16 at 00:14

0 Answers0