[R] SOLVED: Speed Optimization: Faster Way of Accessing array (was: data.frame) in a Loop?
Sven C. Koehler
schween at snafu.de
Thu Nov 23 19:34:12 CET 2006
On Sat, Nov 11, 2006 at 05:22:30AM +0000, Prof Brian Ripley wrote:
> I don't see how this code can work at all. '[<-.data.frame' does not
> accept three arguments, e.g.
> >women[1,2,3] <- 17
> Error in `[<-.data.frame`(`*tmp*`, 1, 2, 3, value = 17) :
> unused argument(s) (3)
> If df is in fact a three-dimensional array you can do
Sorry for the late reply. Yes, df was indeed array(0, c(20, 30, 30)) --
sorry for the confusion!
> df[1:20, 1:30, 20] <- df[1:20, 1:30, 27] + df[1:20, 1:30, 30]
I now tried this myself and the code got quite fast, thank you!
More information about the R-help