Hi.
I'm a real newbie in R, so
I don't know how to apply, a function created by myself...
prediction<-function(a,b)
{
..
}
to a vector...
It doesn't seem to understand
lapply(vector, prediction())...
Anyone can help me?
Thanks in advance,
ana
how to use apply with a function created by ourselfs...?
3 messages · ana kozomara, Spencer Graves, Peter Dalgaard
By default, arithmetic in R is vectorized, with a scalar being a vector
of length 1.
Consider the following example:
prediction <- function(a, b)
{
a+b
}
> prediction(1:3, 4:6)
[1] 5 7 9
hope this helps, spencer graves
ana kozomara wrote:
Hi.
I'm a real newbie in R, so
I don't know how to apply, a function created by myself...
prediction<-function(a,b)
{
..
}
to a vector...
It doesn't seem to understand
lapply(vector, prediction())...
Anyone can help me?
Thanks in advance,
ana
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Spencer Graves <spencer.graves at pdf.com> writes:
By default, arithmetic in R is vectorized, with a scalar being a
vector of length 1.
Consider the following example:
prediction <- function(a, b)
{
a+b
}
> prediction(1:3, 4:6)
[1] 5 7 9 hope this helps, spencer graves
Not sure that was the question... If something else was meant, the
answer might be
lapply(v,prediction,b=5)
or
do.call("prediction",as.list(v))
Rephrasing the question might help...
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907