Im running into a bit of trouble trying to reshape
my dataframe: sites_w_richness
DATASET LINK HERE.
I have been trying to get the data to organize into four columns
- site
- longitude
- latitude
- year
- scenario
- richness value.
Unfortunatley the year (2050 and 2070) and scenario (2.6 and 4.5) data are embedded in the headers of columns 3 to 6 of the dataset. Is there a way to extract the information from the headers and recast the dataframe into the six columns I need?
I have tried this but all I am getting are na's.
#melt and cast to format
require (reshape)
sites_richness<-read.csv('sites_w_richness.csv', header=T)
rich.melt<-melt (sites_richness, id=1:2)
rich.cast<-cast(rich.melt, Longitude ~ Latitude ~ variable ~ value)