我有排序数据
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
我想将数据框转换为一个矩阵,说明Social.Assistance,Danger.Poverty,GINI和S80S20,将区和年作为行的名称:
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
我想有一种简单的方法,我根本看不到......
感谢您的帮助!
答案 0 :(得分:3)
rownames(d) <- paste(d$District, d$Year)
d$District <- NULL
d$Year <- NULL