I want to take a long dataframe and make it wide. Here is an example:
df <- data.frame(date = rep(seq(as.Date("1990/1/1"), as.Date("1999/1/1"), "years"),10), price = seq.int(1, 100), type = c(rep("str",10), rep("str2",10), rep("chr",10), rep("chr2",10), rep("num",10), rep("num2",10), rep("posix",10), rep("posix2",10), rep("date",10), rep("date2",10)))
I want each column to be a different date, but as you can see each of the type
column has its own set of dates from 1990 to 1999. I just want one column for each unique date
and then one row for every type
. Then the entries in the [i,j]th cell would be the price of that type on that day of the year.
So I can imagine it looking like:
type,1990-1-1, 1991-1-1, ..., 1999-1-1
num, 1, 2, ... , 10
chr, 11, 12, ..., 20
...
date, 91, 92, ..., 100