[R] For loop for distinguishing negative numbers
Petr PIKAL
petr.pikal at precheza.cz
Thu Jul 16 11:56:47 CEST 2009
Hi
r-help-bounces at r-project.org napsal dne 15.07.2009 17:59:39:
>
> see ?ifelse
>
> you didn't specify what happens if a value is exactly zero in the
dataset
> and so i've just bundled it in with the negative case:
>
> x <- rnorm(20, 0, 1)
> y<-ifelse(x<=0, 10, 5)
For this simple case you can also use the fact that logical vector can be
used as 0/1 numeric vector.
((x<=0)+1)*5
Regards
Petr
>
> HTH,
> Tony Breyal
>
>
> cmga20 wrote:
> >
> > Hi i am very new to R and I have been trying to change each individual
> > piece of data in a data set to 10 if it is below 0 and 5 if it is
above 0.
> > I know this sounds very easy but i am struggling!!
> >
>
> --
> View this message in context: http://www.nabble.com/For-loop-for-
> distinguishing-negative-numbers-tp24499872p24500973.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list