-1

I have a data set of previous 3 month average stock returns of 200 firms for 92 months. Months are in rows and firms are in columns. Now i have to calculate mean of the top 20 percent of firms given that the values are non-zero. Following is the code:

mmt1<-mean(as.numeric(comb[1,1:40]))

I need to know how to exclude zero values from mean calculation.

J_F
  • 9,314
  • 2
  • 29
  • 52
  • Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Oct 27 '16 at 09:46

1 Answers1

0
mmt1<-mean(as.numeric(comb[, which(colSums(comb)!=0)]))
user124123
  • 1,482
  • 4
  • 28
  • 50