execute array of functions
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 function object, it can be called in the usual way on an argument list by: Some R_Expression(comma separated argument list) e.g.
{y <-function(x) sin(x)+10} (pi/2) ## pi is a known named constant in R
11 Your initial confusion below actually has nothing to do with this: you have confused unquoted names of objects in R with quoted character strings. So, e.g. x <- 1:10 assigns a sequence of numeric values to the name x, which essentially points to where those values are stored in memory. typing
x
at the command line would print the values (by default) typing
"x"
prints the character string "x" -- Bert On Tue, Feb 14, 2012 at 11:02 AM, Muhammad Rahiz
<muhammad.rahiz at ouce.ox.ac.uk> wrote:
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
______________________________________________ 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.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm