I have a data frame df1 such that:
group=c(0,5,3,0,5,3)
year=c("2001","2002","2003", "2010", "2012", "2013")
items=c(12, 10, 15, 5, 10, 7)
df1=data.frame(group, year, items)
I want to create a new column where I assign a value to one year and while leaving the rest at 0. For example, I want it to look like this:
group year items new
1 0 2001 12 1
2 5 2002 10 0
3 3 2003 15 0
4 0 2010 5 0
5 5 2012 10 0
6 3 2013 7 0
Thanks!