I have a function comp(char1, char2, stock)
. It scans a large excel document of stock data of different characteristics, goes through specified sheets in char1
and char2
for a specific stock
(which are in rows and are indexed, so stock = 1
will give the first stock), and returns a new data frame with data for a particular stock's char1
in one column and char2
in another column.
I want to be able to perform this for 100 stocks and combine all of the data frames into one large data frame with two columns: char1 and char2. It doesn't matter if the stocks names are given, I just want all of the data from the char1 and char2 for all 100 stocks in one large data frame of two columns.
I'm a beginner in R, but what I think I need to do is somehow repeat the function 100 times, each time with the input of stock increasing by 1, and then somehow combine all of the data frames (I think with rbind), but I'm not entirely positive.
Here is an example:
AAPL <- comp(char1 = 'RETURNS', char2 = 'EPS' , stock = 1)
will make the data frame
RETURNS EPS
1 17.91 -31.3504
2 17.10 -33.1423
3 22.80 -33.1423
4 22.60 -38.0202
and
DIS <- comp(char1 = 'RETURNS', char2 = 'EPS' , stock = 2)
will make the data frame
RETURNS EPS
1 63.01 17.4997
2 65.32 54.2022
3 58.26 20.6345
4 66.53 20.6345
so if I do rbind(AAPL, DIS)
I get a data frame, of a length of 8, that combines both AAPL and DIS. However, to do this for each one is very tedious, so I want to find a way to have it automated.