Dear all, I would be grateful if you could help me in some way! Well, I have one dataset already uploaded into R with some missing data. My dataset is made of 19 columns, one of these is the sector (naf code). There are many rows relating to the single enterprises. What I want to do is the mean of each variable (column) by sector (naf code), so I type for example: col_5 = data.frame(ave(x[,5], naf, na.rm = TRUE)) Col_5 is referred to the first variable of interest. But since there are some missing data, it results in a series of NA all the column ahead (all the rows are NA). How can I do to discard and not taking into account these missing values??? How could I do to replace missing values with a simple zero just for this analysis??? Thanks so much friends, bye! -- View this message in context: http://r.789695.n4.nabble.com/Dealing-with-missing-data-in-ave-functions-tp3891001p3891001.html Sent from the R help mailing list archive at Nabble.com.