0

I have a dataframe crimes containing crimes. My problem is, that there isn't one row per crime as it should be. Instead there's a variable count for the number of occurences of that crime.

types <- c("Theft", "Robbery", "Assault", "Theft")
count <- c(3, 1, 2, 1)
crimes <- data.frame(type=types, count)

As to the data structure I cannot simply compute frequencies like table(crimes$type). For thefts this would give me a frequency of two, but it should be four instead as the first theft is actually a summary of three thefts.

Is there a way to add additional rows according to the count-variable? I know that sometimes I could also simply sum up count-values per type of crime, but that's not what I want.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
D. Studer
  • 1,711
  • 1
  • 16
  • 35

0 Answers0