ifelse return a value with the same length that logical test.
You need if () {} else {}

 if (y == 5) rep(2, 4) else NA

On Thu, Sep 16, 2010 at 3:58 PM, deven hamilton <dth2@u.washington.edu>wrote:

> I have come across simple problem in R and I was hoping
>
> someone out there could help me out.  Here is the problem: I am trying to
> set up and rep statement with a conditional statement using ifelse.  Here
> is
> simple example.
>
>
>
> > y=5
>
> > o<-ifelse(y==5,rep(2,4),NA)
>
> > o
>
> > [1] 2
>
> >
>
> > If I check my conditional
>
> >
>
> > > y==5
>
> >
>
> > [1] TRUE
>
> >
>
> > And if I check my assignment
>
> >
>
> > > rep(2,4)
>
> >
>
> > [1] 2 2 2 2
>
> >
>
> >So why does this not work within the ifelse statement?  Any help will be
> much appreciated.
>
> >
>
> >
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

