for loop to get tapply means by group across many subjects : I'm trying to do some data analysis as follows: I have about 100 subjects, each of whom have a file containing 40,000 lines of numbers. I also have an index file with 40,000 corresponding lines containing group number. I am trying to get the means of each group, for each subject. I can do this easily for one subject with tapply, like this:

```tapply(df$numbers, df$group, mean)``` 

I can also load in a data frame containing the filenames of each subject's data. What I'd like to do is create a for loop in which I can get the output of the above tapply function for each subject, probably by looping over the filenames and pulling in each one as a new data frame (maybe??). And ultimately I'll want to output this to a .csv with subject names as rows and group names as columns. 

Right now I'm very stuck. Can anyone provide some insight? 

Thanks!

