r - multidimensional arrays of data frames -
i define 3d-array of data.frame(a,b,c,...) can
for (x in 1:4) (y in 1:5) (z in 1:5) { m[x,y,z]$a <- dnorm(1) m[x,y,z]$b <- dnorm(1) m[x,y,z]$c <- dnorm(1) }
it ok too, if data.frame(x,y,z,a,b,c) x,y,z ids , short , effizient way manipulate , read line "x,y,z".
perhaps there better ideas? rid of
ma[x,y,z] <- ... mb[x,y,z] <- ... mc[x,y,z] <- ...
i'm guessing meant rnorm
since populating entire array dnorm(1)
wouldn't seem interesting. lot faster make arrays in 1 pass with:
m <- array( rnorm(4*5*5*3), dims= c(4,5,5, 3) , dimnames=list(x=null, y=null, z=null, lets=c("a","b","c") ) )
so access 4d array, be:
> m[ 1,1,1,"a"] 0.6773062520076687 > m[ 1,1,1,"b"] b 0.6229924684213618 > m[ 1,1,1,"c"] c 0.6899440670029088
or if wanted 3 of them vector:
> m[ 1,1,1, ] b c 0.6773062520076687 0.6229924684213618 0.6899440670029088
Comments
Post a Comment