0

I want to use a for loop to compute cumulative abnormal returns in R and have the dates in column 1, company names (comn) in 2, and stock prices (prccd) in 3. However, to compute abnormal returns I first need to compute the returns and thus need the company names with subsequent stock prices to be able to do this. Now my df looks like this;

Date conm prccd
2016-11-02 X 1
2016-11-02 Y 2
2016-11-02 Z 3

And thus need the data frame to look like:

Date X Y Z
2016-11-02 1 2 3
2016-11-03 2 3 4
2016-11-04 3 4 5
  • Perhaps you want to reshape your data from long to wide? See [this post](https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format)...including `pivot_wider` from `tidyr`... – Ben Jan 09 '22 at 15:28

1 Answers1

0

Maybe you want to transform your dataframe,dcast function in data.table would help. You can see here (how to transform rows to columns in R) for usage

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 09 '22 at 16:27