[R] naming rows/columns in 'array of matrices' | solved
peter dalgaard
pdalgd at gmail.com
Sat Jan 31 09:19:13 CET 2015
> On 30 Jan 2015, at 20:34 , Evan Cooch <evan.cooch at gmail.com> wrote:
>
> The (obvious, after the fact) solution at the bottom. D'oh...
>
[snip]
> Forgot I was dealing with a multi-dimensional array, not a list. So, following works fine. I'm sure there are better approaches (where 'better' is either 'cooler', or 'more flexible'), but for the moment...)
>
> P <- array(0, c(2,2,2),dimnames=list(c("live","dead"),c("old","young"),NULL))
>
> P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T);
> P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T);
>
> print(P);
>
Just for completeness, this also works:
> P <- array(0, c(2,2,2))
> P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T);
> P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T);
> dimnames(P)[[1]] <- c("live","dead")
> dimnames(P)[[2]] <- c("live","dead")
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list