0

I am a beginner with R and I have a question about simple functions such as mean or standard deviation for a big data set. My data shows monthly returns for hedge funds for the past 30 years and has 1550 columns for all hedge funds. I saw that I can calculate the mean with the mean function for a specific column by referring to the column with the name of my dataset and a $ and the no. of the column. However, I was wondering how I can get the mean for every hedge fund (which is every column) without assigning every single column. Thanks in advance for your help!

1 Answers1

1

We can use colMeans

colMeans(df1, na.rm=TRUE)

where 'df1' is the dataset.

or another option would be to loop through the columns and calculate the mean

vapply(df1, mean, na.rm=TRUE, numeric(1))
akrun
  • 874,273
  • 37
  • 540
  • 662