My question is very similar to the one posted here. I am trying to use reshape data to turn CRSP data from long format to wide. I have the tickers of S&P companies stacked in one column and I want to make them the columns instead. In my dataframe I have three columns: "DATE", "TICKER", and "PRC". (PRC is price). I would like instead to have the number of columns equal my unique tickers. I use:
dcast(df, DATE~TICKER, value.var="PRC"), fun.aggregate=length, fill=NaN, drop=FALSE)
This returns the perfect dataframe sorting the time series date on the left and tickers on the right, but just like the question I linked to, I get 1's and NaN's as my values. I like the NaN's, but I would want the 1's to be replaced with the prices of my securities aka the PRC.
I get 1's and 0's because some tickers are missing data, which makes sense as some stocks get into and out of the S&P 500. I just have no idea why the value.var
command is being blatantly ignored.