[BioC] asking for some code

zhihua li lzhtom at hotmail.com
Thu Mar 10 14:12:25 CET 2005


Thanks for all the help! I'm on the border of resolving the problem 
but.........

for the if-else clause, I alwayse got error message when using if..else 
if....else.....statement. I looked it up in the R mannual and found that
R only have a "if....else..." structure, but doesn't have something like  
"if....elseif....elseif......else....."? Does it mean that only two 
conditions can be selected in the conditional execution grammer of R?

for the cut() and switch() clause, I found it's very efficient in 
application to a vector.
but when I wanna use it in a matrix row by row, it's less convenient (or I 
didn't write the
smart code).



>From: Adaikalavan Ramasamy <ramasamy at cancer.org.uk>
>Reply-To: ramasamy at cancer.org.uk
>To: Sean Davis <sdavis2 at mail.nih.gov>
>CC: zhihua li <lzhtom at hotmail.com>, BioConductor mailing list 
<bioconductor at stat.math.ethz.ch>
>Subject: Re: [BioC] asking for some code
>Date: Wed, 09 Mar 2005 14:41:36 +0000
>
>A slightly more intuitive way is to cut() the variable returning labels,
>which you can then feed into switch().
>
># simulate data
>  set.seed(1)
>  x <- runif(5)
>  x
>[1] 0.2655087 0.3721239 0.5728534 0.9082078 0.2016819
>
>
>Let us say that n=0.25 and m=0.6.
>
>my.switch.fn <- function(x ){
>
>    y <- cut( x, breaks=c(0, 0.25, 0.6, 1), labels=FALSE )
>
>    z <- switch(y,
>                "1" = x,
>                "2" = x + 1,
>                "3" = x + 2
>                )
>    return(z)
>}
>
>sapply( x, my.switch.fn )
>[1] 1.2655087 1.3721239 1.5728534 2.9082078 0.2016819
>
>
>In the case of 2 breakpoints, my example does not look much shorter than
>the if-else clause below. The drawback of my suggestion is that you need
>to know the min and max occuring values values (in this case 0 and 1)
>and switch does not have a default value.
>
>Regards, Adai
>
>
>On Wed, 2005-03-09 at 05:56 -0500, Sean Davis wrote:
> > Taking this apart:
> >
> > to find the Q5(quantile):
> >    See ?quantile
> >
> > for each row:
> >    See ?apply
> >
> > if x<n {
> >    do stuff
> > } else if ((x>n) & (x<m)) {
> >    do other stuff
> > } else {
> >    do other other stuff
> > }
> >
> > Sean
> >
> > On Mar 9, 2005, at 4:15 AM, zhihua li wrote:
> >
> > > Dear netters,
> > >
> > > Now I have a matrix at hand. For each row, I want to find the Q5(the
> > > 5th quantile) and the Q95, and put them in a function fyn(), which
> > > will return two numbers n and m(n<m). Then I'll take each element 
(say
> > > x) in the row one by one, and perform a judgment: if x<n, do sub1(x);
> > > if n<=x<=m, do sub2(x); if x>m, do sub3(x). The process goes on
> > > through each row in the matrix. This program isnot very complicated,
> > > but hard enough for me...........So could anybody give me a prototype
> > > of the code?
> > > Thanks a lot!
> > >
> > > _______________________________________________
> > > Bioconductor mailing list
> > > Bioconductor at stat.math.ethz.ch
> > > https://stat.ethz.ch/mailman/listinfo/bioconductor
> >
> > _______________________________________________
> > Bioconductor mailing list
> > Bioconductor at stat.math.ethz.ch
> > https://stat.ethz.ch/mailman/listinfo/bioconductor
> >
>



More information about the Bioconductor mailing list