Reputation: 1111
I have data of the sort
District Year Social.Assistance Danger.Poverty GINI S80S20
Charlottenburg-Wilmersdorf 2011 14.6 12.2 0.33 5.1
Friedrichshain-Kreuzberg 2011 25.8 21.3 0.30 4.3
Lichtenberg 2011 20.8 11.9 0.23 3.1
Marzahn-Hellersdorf 2011 22.1 15.6 0.27 3.8
Mitte 2011 27.9 18.6 0.29 4.1
Neukoelln 2011 29.0 22.5 0.27 3.6
Pankow 2011 13.7 10.4 0.26 3.7
Reinickendorf 2011 19.0 12.5 0.29 4.3
I want to transform the data frame into a matrix stating the Social.Assistance, Danger.Poverty, GINI and S80S20, giving the District and Year as names of the rows:
row_names Social.Assistance Danger.Poverty GINI S80S20
Charlottenburg-Wilmersdorf 2011 14.6 12.2 0.33 5.1
Friedrichshain-Kreuzberg 2011 25.8 21.3 0.30 4.3
Lichtenberg 2011 20.8 11.9 0.23 3.1
Marzahn-Hellersdorf 2011 22.1 15.6 0.27 3.8
Mitte 2011 27.9 18.6 0.29 4.1
Neukoelln 2011 29.0 22.5 0.27 3.6
Pankow 2011 13.7 10.4 0.26 3.7
Reinickendorf 2011 19.0 12.5 0.29 4.3
I guess there is an easy way which I simply do not see.
Upvotes: 1
Views: 111
Reputation: 42629
rownames(d) <- paste(d$District, d$Year)
d$District <- NULL
d$Year <- NULL
Upvotes: 3