Not sure the replies you received make it clear, but the key point is
that functions are first class objects in R like any other objects
(vectors, lists, data frames) and can be assigned, collected into
structures, indexed, etc. in the usual way. Further, if the value of
any R expression is a funct
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Nordlund, Dan (DSHS/RDA)
> Sent: Tuesday, February 14, 2012 11:24 AM
> To: r-help@r-project.org
> Subject: Re: [R] execute array of functions
>
>
On 14/02/2012 2:23 PM, Nordlund, Dan (DSHS/RDA) wrote:
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Muhammad Rahiz
> Sent: Tuesday, February 14, 2012 11:03 AM
> To: x.r-help
> Subject: [R] execute
On Feb 14, 2012, at 2:32 PM, Stavros Macrakis wrote:
That won't work because R has special rules for evaluating things in
the
function position. Examples:
*OK*
min(1:2)
"min"(1:2)
f<-min; f(1:2)
do.call(min,list(1:2))
do.call("min",list(1:2)) # do.call converts string->function
*Not
On Feb 14, 2012, at 2:23 PM, Nordlund, Dan (DSHS/RDA) wrote:
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
project.org] On Behalf Of Muhammad Rahiz
Sent: Tuesday, February 14, 2012 11:03 AM
To: x.r-help
Subject: [R] execute array of functions
Hi all
That won't work because R has special rules for evaluating things in the
function position. Examples:
*OK*
min(1:2)
"min"(1:2)
f<-min; f(1:2)
do.call(min,list(1:2))
do.call("min",list(1:2)) # do.call converts string->function
*Not OK*
("min")(1:2) # string in function positi
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Muhammad Rahiz
> Sent: Tuesday, February 14, 2012 11:03 AM
> To: x.r-help
> Subject: [R] execute array of functions
>
> Hi all,
>
> I'm
Hi all,
I'm trying to get the min and max of a sequence of number using a loop
like the folllowing. Can anyone point me to why it doesn't work.
Thanks.
type<- c("min","max")
n <- 1:10
for (a in 1:2){
print(type[a](n)) }
--
Muhammad
8 matches
Mail list logo