I want to calculate a summary of the transition between variables. I have a dataset that looks like this:
id x.2012 y.2012 x.2013 y.2013
1 1 0 0 1
2 0 1 1 0
3 0 1 1 0
4 1 0 1 0
And I want to find the transition table:
x.2013 y.2013
x.2012 1 1
y.2012 2 0
So, it calculates how many values were changed for x, so zero changes from yto ynext year and 2 for y -> x.
I have no idea how to calculate such a table; I looked through reshape2and tidyr, but without success.
Ideally, I’m looking for a package like reshape(I can’t think of keywords to search Google for this ...) that look like a function cast, while funaccepting a subset my.df:
modern.cast(my.df, .(x.2012, y.2012) ~ .(x.2013, y.2013), fun)
source
share