[R] Calculating the mean in one column with empty cells
Berend Hasselman
bhh at xs4all.nl
Fri Oct 5 15:01:55 CEST 2012
On 05-10-2012, at 11:27, fxen3k wrote:
> Hi all,
>
> I recently tried to calculate the mean and the median just for one column.
> In this column I have numbers with some empty cells due to missing data.
> So how can I calculate the mean just for the filled cells?
> I tried:
> mean(dataSet2$ac_60d_4d_after_ann[!is.na(master$ac_60d_4d_after_ann)],
> na.rm=TRUE)
> But the output was different to the calculation I died in Microsoft Excel.
>
No data ==> no can answer question.
What did you expect?
What did Excel give you?
But you are trying to calculate the mean of dataSet2$ac_60d_4d_after_ann and indexing with the indices of non-NA numbers of master$ac_60d_4d_after_ann.
mean(dataSet2$ac_60d_4d_after_ann, na.rm=TRUE)
should do what you want.
Berend
More information about the R-help
mailing list