[R] Odp: mean and sd with number of values?

Petr PIKAL petr.pikal at precheza.cz
Fri Mar 7 14:55:53 CET 2008


Hi

Martin Kaffanke <technik at roomandspace.com> napsal dne 06.03.2008 18:05:03:

> 
> Am Donnerstag, den 06.03.2008, 17:47 +0100 schrieb Petr PIKAL:
> > Hi
> > 
> > r-help-bounces at r-project.org napsal dne 06.03.2008 17:41:06:
> > 
> > > Hi there,
> > > 
> > > When i do 
> > > 
> > > mean(fl[1:20], na.rm=T)
> > 
> > e.g.
> > 
> > sum(!is.na(fl[1:20]))
> 
> This seems to give me a sum of all the items.
> 
> But I'd like to have it per column.
> 
> > mean(fl[1:20])
>            aids      angststoer        autismus bauchspduekrebs
> prostata 
>      -0.7474884      -1.0475500      -0.6267267              NA
> -1.7318179 
>         fraudep         manndep       hautkrebs     herzinfarkt
> leukaemie 
>      -1.2919841      -1.5124280      -0.3202036      -0.8246589
> 0.7550549 
>     lungenkrebs manischdepresiv      magenkrebs      magersucht
> mannmagsucht 
>      -1.2451753      -1.9726160       1.4548394      -0.6242250
> NA 
>     osteoporose           panik   schizophrenie    schlaganfall
> zwangsstoer 
>      -1.7974270              NA      -1.8634089              NA
> -1.5056106 
> 
> > mean(fl[1:20], na.rm=T)
>            aids      angststoer        autismus bauchspduekrebs
> prostata 
>      -0.7474884      -1.0475500      -0.6267267       1.2168804
> -1.7318179 
>         fraudep         manndep       hautkrebs     herzinfarkt
> leukaemie 
>      -1.2919841      -1.5124280      -0.3202036      -0.8246589
> 0.7550549 
>     lungenkrebs manischdepresiv      magenkrebs      magersucht
> mannmagsucht 
>      -1.2451753      -1.9726160       1.4548394      -0.6242250
> -0.3765245 
>     osteoporose           panik   schizophrenie    schlaganfall
> zwangsstoer 
>      -1.7974270      -1.2328361      -1.8634089      -1.7165059
> -1.5056106 
> 
> > sum(!is.na(fl[1:20]))
> [1] 892

Then why not compute it across columns either by apply or by colSums

apply(!is.na(fl), 2, sum)
colSums(!is.na(fl))

Regards
Petr


> 
> So I'd like to have it like the mean, to see how many data is calculated
> by na.rm=T per column?
> 
> Thanks,
> Martin
> [příloha signature.asc odstraněna uživatelem Petr PIKAL/CTCAP] 



More information about the R-help mailing list