s-news
[Top] [All Lists]

Re: [S] apply with NA summary

To: s-news@wubios.wustl.edu
Subject: Re: [S] apply with NA summary
From: Tim Hesterberg <timh@statsci.com>
Date: Thu, 29 Jul 1999 13:57:29 -0700 (PDT)
In-reply-to: <199905301631.LAA14092@uhdux2.dt.uh.edu> (message from Erin Hodgess on Sun, 30 May 1999 11:31:46 -0500 (CDT))
References: <199905301631.LAA14092@uhdux2.dt.uh.edu>
Reply-to: timh@statsci.com (Tim Hesterberg)
Sender: owner-s-news@wubios.wustl.edu
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

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [S] apply with NA summary, Tim Hesterberg <=