[R] How ti perform a substitution in a loop?

Berend Hasselman bhh at xs4all.nl
Sat Aug 14 09:43:18 CEST 2010



Saji Ren wrote:
> 
> ...
> I have a data series of 500 data, and I want to limit the value of it to
> be less than 1.
> Below is my code:
> 
>>for (i in 1:500)
> +if( x[i] > 1)
> +x[i] = 1
> 
> but the system told me it's wrong. Can anyone told me the reason?
> 

You don't show the error message.
Read the posting guide.

Try

?pmin

And

x <- pmin(x,1)

will probably do what you require.

/Berend

-- 
View this message in context: http://r.789695.n4.nabble.com/How-ti-perform-a-substitution-in-a-loop-tp2325007p2325062.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list