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
|