Message-ID: <OF21DEE96A.12D94FEE-ONC1257567.00308411-C1257567.0030DFEF@precheza.cz>
Date: 2009-02-24T08:54:45Z
From: PIKAL Petr
Subject: Odp: Help How to use a loop to do pair comparison
In-Reply-To: <000001c99640$03830000$0a890000$@com>
Hi
r-help-bounces at r-project.org napsal dne 24.02.2009 06:23:23:
> 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
Well. It is a little cryptic what you want.
Suppose you have 100 x values. What is x value number 101?
If you want to check if subsequent value is bigger or smaller then
previous one use
diff(x) and test diff(x)>0.
Regards
Petr
>
>
>
> 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 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.