I am trying to take a data frame that looks like this:
desc<- c("a", "b", "c", "d")
df <- data.frame(matrix(ncol = 3 , nrow = 12))
colnames(df)<- c("Date", "Value", "Desc")
df[1:4,'Date'] <- "2017-01-01"
df[5:8,'Date'] <- "2018-01-01"
df[9:12,'Date'] <- "2019-01-01"
df[1:12,'Desc'] <- desc
df[1:12,'Value'] <- seq(1:12)
head(df)
And change it into one that has the dates as columns and "Desc" as row names, like this:
2017-01-01 2018-01-01 2019-01-01
a NA NA NA
b NA NA NA
c NA NA NA
d NA NA NA
I have gotten as far as a few if loops to get my DF set up but cannot for the life of me think of how to pull out the value and put it into the new dataframe. Any help would be so appreciated at this point! I am also a student so I apologize if I missed any steps in posting this or did it the wrong way.
My brain couldn't wrap itself around how to match both values and then put it in the right position.