[R] Applying a function to a vector
Carlos J. Gil Bellosta
cgb at datanalytics.com
Mon Oct 31 16:38:58 CET 2005
You should then try apply. See ?apply.
For instance:
a <- matrix(c(1:10), 5, 2)
apply(a, 1, function(x) x[1] + 100 * x[2])
This way you can disaggregate the components of your input (that is not a
singleton) and use them inside your function separately.
Carlos J. Gil Bellosta
http://www.datanalytics.com
Quoting Florent Bresson <f_bresson at yahoo.fr>:
> I just have a try with sapply. The problem is that my
> function pbeta2 has two parameters z and p (wich is a
> vector of two parameters). If I use sapply , R returns
> a message incicating that parameter p is missing. It
> is a problem since both z and p are varying along my
> data.frame.
More information about the R-help
mailing list