Hi Patrick, Thank you for your hint. I got it works.
> x<-1:3 > result<-ifelse(test=outer(X=x,Y=x,FUN=">"), yes="Big", + ifelse(test=outer(X=x,Y=x,FUN="<"), yes="Small", "Equal")) > result [,1] [,2] [,3] [1,] "Equal" "Small" "Small" [2,] "Big" "Equal" "Small" [3,] "Big" "Big" "Equal" > Thanks Chunhao > Date: Tue, 24 Feb 2009 10:02:29 +0000 > From: pbu...@pburns.seanet.com > To: tc...@hotmail.com > CC: r-help@r-project.org > Subject: Re: [R] Help How to use a loop to do pair comparison > > One possible first step could be: > > ifelse(outer(x, x, '>'), 'Big', 'Small') > > > Patrick Burns > patr...@burns-stat.com > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of "The R Inferno" and "A Guide for the Unwilling S User") > > Chunhao Tu wrote: > > Hi R users, > > > > I have a question. How can I use for loop to do pair comparisons. For > > example, > > > > > >> x<-c(1,2,3) > >> > > > > > >> result<-matrix(data=NA, nrow=choose(3,2), ncol=1) > >> > > > > > >> for(i in 1: length(x)) > >> > > > > + { result[i,]<-ifelse(x[i] > x[i+1], yes="Big", no="Small") > > > > + result} > > > > > >> result > >> > > > > [,1] > > > > [1,] "Small" > > > > [2,] "Small" > > > > [3,] NA > > > > > > > > I want to compare (1 vs. 2), (1 vs. 3), (2 vs.3) > > > > I know I miss something but I just can not get it work. Could anyone give me > > a hint? > > > > > > > > Appreciate, > > > > Chunhao > > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. > > > > > > _________________________________________________________________ Show them the way! Add maps and directions to your party invites. [[alternative HTML version deleted]] ______________________________________________ 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.