I'm recently working with data as
year <- c('1990', '1990', '1994', '2000', '2012')
n1 <- c(30, 70, 20, 31, 10)
n2 <- c(40, 60, 20, 21, 8)
r1 <- c(0, 9, 3, 4, 4)
r2 <- c(3, 9, 1, 2, 0)
data <- data.frame(year, n1, n2, r1, r2)
I want to split each row into two rows, where row1 includes n1 and r1 and row2 includes n2 and r2.
The desired result would be like this;
> data
year type n r
1 1990 0 30 0
2 1990 1 40 3
3 1990 0 70 9
4 1990 1 60 9
5 1994 0 20 3
6 1994 1 20 1
7 2000 0 31 4
8 2000 1 21 2
9 2012 0 10 4
10 2012 1 8 0