0

I was hoping to get some help reorganizing my data table.

Right now I have a data table that looks something like this (this is fake data):

city       year  income_per_capita
Boston     1998       21344.32
Boston     1999       23454.45
Boston     2000       21628.31
London     1998       31526.23
London     1999       36889.56
London     2000       34521.12
Chicago    1998       25643.30
Chicago    1999       21452.24
Chicago    2000       23465.35

I want to make it look like this

          1998        1999         2000

Boston   21344.32    23454.45      21628.31
London   31526.23    36889.56      34521.12
Chicago  25643.30    21452.24      23465.35

I was told to try the melt() function, but I can't seem to figure it out. I'm very new to R. I tried using id.vars and variable.name but I still can't get it to where I want it to be.

Thank you and please let me know if I can provide more details!

imdinos
  • 49
  • 5

0 Answers0