[R] Problem labeling arrays

From: downunder03 <larsfromspace_at_web.de>
Date: Tue 02 Jan 2007 - 22:50:30 GMT

Hi all. I'am sitting for hours. I have a problem labelling arrays. I am loosing labels for higher dimensions than matrices. Has anyone already faced that problem? There must be some direct way without writing complicated functions. Thanks for any hint. greetings lars

x<-matrix(sin(1:90),nrow=100,ncol=9)
dimnames(x)[[2]]<-c("F1_5", "F2_5", "F3_5","F4_5", "F5_5","F6_5", "F7_5", "F8_5", "F9_5")

partialCorr <- function (cond, mat)

        cor(qr.resid(qr(cbind(1, mat[, cond])), mat[, -cond]))

# matrix keep label

d=partialCorr(c(3,2),x)
d

# array looses label

bsp1 <- array(0, c(7,7,36))
k <- 0
for(i in 1:8) for(j in (i+1):9) {

    k <- k+1
    bsp1[, , k] <- partialCorr(c(i, j), x) }
bsp1
# I tried something to label inside the loop
bsp1 <- array(0, c(7,7,36))
k <- 0
for(i in 1:8) for(j in (i+1):9) {

    k <- k+1
    bsp1[, , k] <- partialCorr(c(i, j), x)     dimnames(bsp1[,,k])=dimnames(partialCorr(c(i,j), x)) }
bsp1
# I tried something to label outside the loop but can't directy adress the
array
labels <- array(0, c(7,1,36))
k <- 0
for(i in 1:8) for(j in (i+1):9) {

    k <- k+1
    labels[, , k] <- as.vector(rownames(partialCorr(c(i,j), x))) }
labels
for (k in 1:36){
dimnames(bsp1[,,k])=list(c(labels[,1,k]),c(labels[,1,k])) }
bsp1

-- 
View this message in context: http://www.nabble.com/-R--Problem-labeling-arrays-tf2910585.html#a8132366
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Wed Jan 03 09:56:13 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 02 Jan 2007 - 23:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.