Hi Elahe, You can do so using the mean function, mean(), by specifying an additional argument, na.rm = TRUE. In this case, you specify that you wish to remove (rm) all NA values in the columns.
—> mean($X2016.Q1, na.rm = T). By default, na.rm is set to FALSE, so mean() will return a NA value. Hope this helps! Regards, Bo Lin > On 2 Mar 2017, at 6:57 PM, ch.elahe via R-help <r-help@r-project.org> wrote: > > > > The question seems easy but I could not find an answer for it. I have the > following column in my data frame and I want to take average of the column > excluding the number of NAs. > > $X2016.Q1 : int 47 53 75 97 NA NA 23 NA 43 NA .... > > Does anyone know how to do that? > Thanks for any help > Elahe > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.