I have a problem with the reshape function. I tired it for while now, but it just doesn’t work. My data looks like this:
KeyItem Year Value
Income 2011 10000
Income 2010 29299
Depth 2010 29393
Market Cap 2010 39393
Depth 2011 20000
Market Cap 2011 30000
and I need it to look like this for my function:
KeyItem 2011 2010
Income 10000 29299
Depth 20000 29393
Market Cap 30000 39393
The easiest way is to use the
dcastfunction in thereshape2package. First, load in the data:then load the package:
Finally, just the
dcastfunction:to get:
To go the other way, just use the
meltfunction:You can reorder your columns in the usual way: