I am trying to wrangle some data for my masters thesis, and am struggling to restructure a data frame.
I have a data frame that looks like this table, with three variables
Basically I want to flip it on its side so that Sample goes along the top with two rows underneath for farm and year. I have tried these approaches so far (dataframe is called labnums):
labnums <- labnums %>%
spread(sample, farm + year)
labnums <- xtabs(year + farm~sample, labnums)
however neither work. Does anyone have any idea how I can make it work? (Also sorry for having to use an image, I've never posted on here before)
Thanks!