Shape Data from Wide to Long R

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Shape Data from Wide to Long R

I have 9 different daily variables (share price, bid price, ask price, shares outstanding, etc...) for appr. 900 companies over 2 years. In the first column is the date, and then the following 9 columns are the 9 variables for the first firm (price1, bid price1, ask price1,...), followed by the variables for the 2nd firm (price2, bid price2, ask price2,...) etc...

I want to shape the data into the long format with the first column as the date, second column as the firm number and then the 9 variables.

I have already tried it with the gather() function and have 4 columns now with the date, firm number, variable and the value. But I donĀ“t know how to shape it that I get the 9 variables into 9 columns?

Thanks a lot for any help.