s-news
[Top] [All Lists]

Re: tapply()

To: lambert.winifred@ensco.com
Subject: Re: tapply()
From: Terry Therneau <therneau@mayo.edu>
Date: Thu, 13 Dec 2001 08:44:14 -0600 (CST)
Cc: s-news@lists.biostat.wustl.edu, "Atkinson, Elizabeth J." <atkinson@mayo.edu>
Reply-to: Terry Therneau <therneau@mayo.edu>
Winnie Lambert asks how to get tapply to report numbers for a fixed set
of levels, i.e.,
        temp <- tapply(x, hours, mean)
        
where "hours" has numbers from 1 to 24, but in certain data sets not all of
the hours of the day have a representative.

 To get all of the hours, use
        temp <- tapply(x, factor(hours, levels=1:24), mean)
                
This will result in a solution vector of length 24, containing NA for levels
that did not occur.
        
        
                Terry Therneau
                
                
                                


<Prev in Thread] Current Thread [Next in Thread>
  • tapply(), Winnie Lambert
    • Re: tapply(), Terry Therneau <=