From: ANA KOZOMARA (firstname.lastname@example.org)
Date: Mon 21 Apr 2003 - 19:43:19 EST
hey thanks a lot...
finally I decided to write my own fonction which will do it...
I was completely lost with rbind, mode="list"...
I find slightely weird the R-kind-of-thinking...:)))
Anyway, i'm trying to acomplish my project in R and not c spirit,
so i'll try what u suggests,
..hey, thanks a lot again...
Od: Peter Dalgaard BSA <email@example.com>
Za: ANA KOZOMARA <firstname.lastname@example.org>
Tema: Re: [R] how to use apply with a function created by ourselfs...?
Primljena: 21 Apr 2003 11:27:48
"ANA KOZOMARA" <email@example.com> writes:
> ..hey thanks for the answer, both of you...
> but :-(, I don't seem to have an answer to my problem...
> I tried with what u suggested, but it doesn't work yet...
> so I will precise it...
> I have a data frame...
> and I would like to apply the function "prediction" which acts on two
> to my data frame,I mean to all the rows of my data frame...
> something like a function "Map" in Mathematica...
> Shortly, I want to apply function "prediction" to a list of arguments,
> to a single argument...
> I hope now it is more clear...
> Thanks for the answers once more,
> best regards,
It depends on your prediction function. The best thing is to arrange
that it vectorizes over its arguments, as Spencer Graves suggested.
Then it's just
or, if you want something that works for more than two rows,
if your prediction() does not vectorize (i.e. a and b has to be
scalars), you can do two things:
pr.row <- function(row) do.call("prediction",row)
apply(df, 1, pr.row)
or create a vectorized prediction(), as in
pr.vec <- function(a,b)
-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (firstname.lastname@example.org) FAX: (+45) 35327907
______________________________________________ Remail@example.com mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:42 EST