Question

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...

Thank you for any help!

Was it helpful?

Solution

rownames(d) <- paste(d$District, d$Year)
d$District <- NULL
d$Year <- NULL
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top