HI,

I think I understand what you meant.  This will output all those states where 
contribution for Obama is higher than all the other candidates.

dat1<-read.table(text="
                  AL  AR  CA  NY
Doug    250 250 250  NA
Jennifer  20 340 300 100
Michele  250 500 250  60
Obama    15  45 520 600
",header=TRUE,stringsAsFactors=FALSE,sep="")
 res<-unlist(lapply(apply(dat1,2,function(x) x[!is.na(x)]),function(x) 
x[all(x["Obama"]>x[names(x)!=names(x)[grep("Obama",names(x))]])]))
res[grep("Obama",names(res))]
#CA.Obama NY.Obama 
  #   520      600 
A.K.



----- Original Message -----
From: noobmin <pseudov...@hotmail.com>
To: r-help@r-project.org
Cc: 
Sent: Tuesday, October 23, 2012 3:00 PM
Subject: Re: [R] How to use tapply with more than one variables grouped

I meant where obama has higher value compared to other candidates. Looking at
the column NY, Obama has the highest. So to state that he wins. Looking for
AR column, Michelle wins. I JUST want to list where obama wins.

Thank you! This seems to work, just do not understand why you used a
threshold? 

I will study your solution, thanks again!



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-use-tapply-with-more-than-one-variables-grouped-tp4646948p4647203.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.


______________________________________________
R-help@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.

Reply via email to