If possible I would like to apply a function, that contains a "reduce"
statement, across the rows of 2d array. This code works for me right up
until the last. Can it be done or is there a better way? My next challenge
is to pass it a vector of starting values, i.e. each row will have a
different initial value.

func1 <- function (x,y) {x * 0.6}
Reduce(func1, x = seq_len(10), accumulate = TRUE, init = 3)

totalfunc <- function (x) {Reduce(func1, x = seq_len(10),
       accumulate = TRUE, init = 3)
                       }

totalfunc(0)

startarray <- t(array(1:100, c(10,10)))

newarray <- apply(x = startarray, margin = 1, fun = totalfunc)


Thanks

J

-- 
Jim Maas

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to