Skip to content
Prev 79949 / 398502 Next

Applying a function to a vector

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>: