[R] easy debugging

Martin Maechler maechler at stat.math.ethz.ch
Wed Jul 28 13:12:40 CEST 2010


>>>>> "ycw" == ying chen wang <gracedrop.wang at gmail.com>
>>>>>     on Mon, 26 Jul 2010 17:10:24 -0400 writes:

    ycw> Yes, thanks. Just found out the solution. Thanks for the help.
    ycw> Just started R. Not familiar with its environment.

    ycw> G

    ycw> On Mon, Jul 26, 2010 at 5:08 PM, jim holtman <jholtman at gmail.com> wrote:

    >> Is this what you want:
    >> 
    >> > equated<-c(111.0,112.06, 112.9, 113.8, 115.0, 116.2, 117.0, 118.0, 120.5,
    >> + 120.5, 120.5)
    >> > equated[equated > 120] <- 120
    >> > equated
    >> [1] 111.00 112.06 112.90 113.80 115.00 116.20 117.00 118.00 120.00
    >> 120.00 120.00
    >> >

Note that for the particular question,

     pmin(120, equated)

is more efficient than any of the other versions you've
mentioned.

Martin Maechler, ETH Zurich

    >> 
    >> 
    >> You should read up on 'indexing' in the R Intro paper.
    >> 
    >> On Mon, Jul 26, 2010 at 1:26 PM, ying_chen wang
    >> <gracedrop.wang at gmail.com> wrote:
    >> > I am new to R. Used to use FORTRAN. R is so different from FORTRAN. The
    >> > following codes would work in FOTRAN. I am trying to put an upper limit
    >> at
    >> > 120. If the score is > 120, it is assigned 120. Or else, keep the
    >> original
    >> > values.
    >> >
    >> > version 1:
    >> >
    >> > equated<-11
    >> > result<-11
    >> > equated<-c(111.0,112.06, 112.9, 113.8, 115.0, 116.2, 117.0, 118.0, 120.5,
    >> > 120.5, 120.5)
    >> >
    >> > for (i in 1:11){
    >> > if (equated > 120) result[i]<-120
    >> > if (equated < 120) result[i]<-equated[i]
    >> > result<-result
    >> > result
    >> > }
    >> > result
    >> >
    >> > version2:
    >> >
    >> > if (equated > 120) result<-120
    >> > if (equated < 120) result<-equated
    >> >
    >> >
    >> >
    >> > If any of you can help, I would appreciate that.
    >> >
    >> > G
    >> >
    >> >        [[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.
    >> >
    >> 
    >> 
    >> 
    >> --
    >> Jim Holtman
    >> Cincinnati, OH
    >> +1 513 646 9390
    >> 
    >> What is the problem that you are trying to solve?
    >> 

    ycw> [[alternative HTML version deleted]]

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



More information about the R-help mailing list