First of all, I am using the ukpolice library in R and extracted data to a new data frame called crimes. Now i am running into a new problem, i am trying to extract certain data to a new empty data frame called df.shoplifting if the category of the crime is equal to "shoplifiting" it needs to add the id, month and street name to the new dataframe. I need to use a loop and if statement togheter.
EDIT: Currently i have this working but it lacks the IF statemtent:
for (i in crimes$category) {
 shoplifting <- subset(crimes, category == "shoplifting", select = c(id, month, street_name))
 names(shoplifting) <- c("ID", "Month", "Street_Name")
}
What i am trying to do:
for (i in crimes$category) {
if(crimes$category == "shoplifting"){
data1 <- subset(crimes, category == i, select = c(id, month, street_name))
  }
}
It does run and create the new data frame data1. But the data that it extracts is wrong and does not only include items with the shoplifting category..
 
     
     
    