Suppose I have a coefficient (in data.frame) that represents years:
year
1 2012
2 2012
3 2012
4 2013
5 2013
6 2013
7 2014
8 2014
9 2014
I would like to create (in this case) three new columns in data.frame and finally:
y2012 y2013 y2014
1 1 0 0
2 1 0 0
3 1 0 0
4 0 1 0
5 0 1 0
6 0 1 0
7 0 0 1
8 0 0 1
9 0 0 1
I can, of course, write a bunch of ifelse statements, but that seems very inconvenient.
source
share