[R] easy debugging

jim holtman jholtman at gmail.com
Mon Jul 26 23:08:56 CEST 2010


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
>


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?



More information about the R-help mailing list