I'm very new to R and I'm not very good at it still. I am working with a dataframe that looks like this:
ID ESG var Y2009 Y2010 Y2011
A ESG score 5.1 3.5 4.8
A Emissions 3.0 1.4 1.3
B ESG score 6.5 4.6 2.1
B Emissions 3.6 1.9 1.6
but I would like to reshape it and make it look like:
ID YEARS ESG score Emissions
A 2009 5.1 3.0
A 2010 3.5 1.4
A 2011 4.8 1.3
B 2009 6.5 3.6
B 2010 4.6 1.9
B 2011 2.1 1.6
I need one year variable that takes three values (2009, 2010, 2011) and to go to two ESG variables ( ESG score and Emission) that take the corresponding numerical value.
I tried to use the function reshape() and melt() but I couldn't find any good way. Can someone help me please?