EDIT: although this question has been closed, it is helpful to note that the answers provided use a very different approach (with dplyr) than the original question asked in 2012(!). These new answers may be helpful for different users.
I have a datasets of sites with the min and max years when they were operational. But I want to expand this dataset so that each year the site was operational has a row.
For example:
set.seed(42)
df <- data.frame(
site = rep(LETTERS[1:10]),
minY = sample(1980:1990, 10),
maxY = sample(2000:2010, 10)
)
df
site minY maxY
1 A 1980 2007
2 B 1984 2006
3 C 1990 2003
4 D 1988 2000
5 E 1981 2004
6 F 1983 2005
7 G 1986 2008
8 H 1989 2001
9 I 1987 2009
10 J 1985 2010
So in my final dataset Site A would have a 28 rows (one for each year it was operating).
I've been trying to use the complete function, but I keep getting an error message:
complete(df,
nesting(site),
fill = list(value1 = minY, value2 = maxY))
Error in vec_is_list(replace) : object 'minY' not found