[18791] in s-news-athena
Re: [S] apply with NA summary
daemon@ATHENA.MIT.EDU (Tim Hesterberg)
Thu Jul 29 17:10:02 1999
Date: Thu, 29 Jul 1999 13:57:29 -0700 (PDT)
Message-Id: <199907292057.NAA01889@quake.statsci.com>
From: Tim Hesterberg <timh@statsci.com>
To: s-news@wubios.wustl.edu
In-Reply-To: <199905301631.LAA14092@uhdux2.dt.uh.edu> (message from Erin
Hodgess on Sun, 30 May 1999 11:31:46 -0500 (CDT))
Reply-To: timh@statsci.com (Tim Hesterberg)
Erin Hodgess wrote:
> If I wish to sum across the columns of a matrix, x, I would
> use xt <- apply(x,1,sum)
>
> That works fine.
>
> Now, suppose in some of my entries, I have NAs.
> How could I pass the na.rm=T part in to the apply, please?
Hodgess summarized the responses:
>xt <- apply(x,1,sum,na.rm=T)
(1) Those answers give sums across rows, not columns.
(2) If you are using S+4.0 or later, use one of
colSums(x, na.rm=T)
rowSums(x, na.rm=T)
which are much faster than using apply.
(3) Note also
rowMeans, colMeans
rowVars, colVars
rowStdevs, colStdevs (these two are new in S+2000)
========================================================
| Tim Hesterberg Research Scientist |
| timh@statsci.com www.statsci.com/Hesterberg |
| (206)283-8802x319 MathSoft, Inc. |
| (206)283-0347 (fax) 1700 Westlake Ave. N, Suite 500 |
| Seattle, WA 98109-3044, U.S.A. |
========================================================
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news