I want to clean my stock data which is in the following format (the PERMNO is the identifier for the stock/company):
To work better with the data, I want to create a new column for each stock/PERMNO with all prices underneath (of course matching the respective date), so that i have the price data in long format in individual columns for each company respectively.
If have managed to group the data by PERMNO with the following line, but I have no idea how to put it in new columns now.
DT[,print(.SD),by=PERMNO])
YESSS!!! Wow I am so thankful! I am new with R and just started my master thesis, and I literally sat on this stupid problem for an entire day now. Thank you so much!!!
Hi @Pia! Welcome! I’m glad to see someone here was able to get you unstuck! I hope you’ll keep posting questions as you keep learning .
You might also want to take a look at our Tips for Writing R-related Questions to learn about how to prepare your questions to get the best help here. For example, while it’s pretty natural for people to start out posting screenshots of their data, that’s actually a fairly heavy lift for your helpers (they have to re-type all your data by hand just to get started poking at your problem). The tips page links to several resources for learning more helper-friendly ways of composing your questions.