Skip to content
Prev 308864 / 398503 Next

How to use tapply with more than one variables grouped

Hi,

Just a modification of David's method:

apply(dat1,2,function(x) names(which.max(x[!is.na(x)]))=="Obama")
#?? AL??? AR??? CA??? NY 
#FALSE FALSE? TRUE? TRUE 
names(dat1)[apply(dat1,2,function(x) names(which.max(x[!is.na(x)]))=="Obama")] 
#[1] "CA" "NY"
A.K.



----- Original Message -----
From: David Winsemius <dwinsemius at comcast.net>
To: noobmin <pseudovoid at hotmail.com>
Cc: r-help at r-project.org
Sent: Tuesday, October 23, 2012 8:45 PM
Subject: Re: [R] How to use tapply with more than one variables grouped
On Oct 23, 2012, at 1:25 PM, noobmin wrote:

            
Perhaps:
?  AL? ? AR? ? CA? ? NY 
FALSE FALSE? TRUE? TRUE 

Or perhaps:
[1] "CA" "NY"
David Winsemius, MD
Alameda, CA, USA

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.