I currently have:
Country.Name 1995 1996 1997 ... 2013
Country1
Country2 (numeric data)
Country3
-This format makes it difficult to graph the data for each country, and compare them, since the header columns are individual years
I want:
Year Country1 Country2 Country3
1995
1996
1997 (numeric data)
...
2013
Assuming you have this data frame
df
, see data below.First you have to transpose all data frame except the first column. The result being a matrix that we need to convert to a data frame. Finally, we assign as column names of
df2
the first column of the original data framedf
.Output:
Data:
See more: http://www.r-statistics.com/tag/transpose/