Re: [R] function inside ifelse

2009-06-15 Thread Stavros Macrakis
Of course functions can be used inside ifelse.  They should return vectors.

Be careful of the effect of recycling:

ifelse(c(F,T,F,T,F,T),1:3,10:20)
[1] 10  2 12  1 14  3

with functions:

> f<- function(x) x/mean(x)
> ifelse(c(F,T,F,T,F,T),sqrt(1:3),f(10:20))
[1] 0.667 1.4142136 0.800 1.000 0.933 1.7320508

  -s

On Mon, Jun 15, 2009 at 10:39 AM, Grze¶  wrote:

>
> Could you tell me, if it's possible to create ifelse and put function
> inside, for example:
>
> code{
> ifelse ((is.na(vek)), call_fun_1(arguments), call_fun_2(arguments))
>
> call_fun_1 <- function(arguments)
> { sth...
> }
> }
> --
>

[[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.


Re: [R] function inside ifelse

2009-06-15 Thread Grześ


Grześ wrote:
> 
> Hi,
> 
> Could you tell me, if it's possible to create ifelse and put function
> inside, for example:
> 
> code{
> ifelse ((is.na(vek)), call_fun_1(arguments), call_fun_2(arguments))
> 
> call_fun_1 <- function(arguments)
> { sth...
> }
> }
> 

Ok, I found answer alone! This is possible, thanks for everybody !!! ;)
-- 
View this message in context: 
http://www.nabble.com/function-inside-ifelse-tp24035739p24036034.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] function inside ifelse

2009-06-15 Thread Grześ

Hi,

Could you tell me, if it's possible to create ifelse and put function
inside, for example:

code{
ifelse ((is.na(vek)), call_fun_1(arguments), call_fun_2(arguments))

call_fun_1 <- function(arguments)
{ sth...
}
}
-- 
View this message in context: 
http://www.nabble.com/function-inside-ifelse-tp24035739p24035739.html
Sent from the R help mailing list archive at Nabble.com.

__
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.