I have a data frame containing information on incidents for countries around the world. The structure of the data frame is similar to the following example:
a <- data.frame(country = c("AAA" , "BBB" , "CCC") ,
incident = rep("disaster" , times = 3) ,
'start year' = c(1990 , 1995 , 2011) ,
'end year' = c(1993 , 1995 , 2012))
giving a
:
country incident start.year end.year
1 AAA disaster 1990 1993
2 BBB disaster 1995 1995
3 CCC disaster 2011 2012
I would like to transform this so that each row contains the incident for each individual year instead of only the interval. Ideally, it would look like something like this:
country incident year
1 AAA disaster 1990
2 AAA disaster 1991
3 AAA disaster 1992
4 AAA disaster 1993
5 BBB disaster 1995
6 CCC disaster 2011
7 CCC disaster 2012
Is there an optimal code that can transform this to include a start and end year?