012 4:58 PM
To: r-help@r-project.org
Subject: RE: [R] How to create arbitrary number of loops in R
Thanks, ilai and Christian! Both codes are working but I have one more question.
Both codes return results in array format. In my original code, I get icc value
from icc(data)$value and use loop to
vector?
>
>
>Thanks!
>Daisy
>
>-Original Message-----
>From: ila...@gmail.com [mailto:ila...@gmail.com] On Behalf Of ilai
>Sent: Thursday, March 29, 2012 10:46 AM
>To: Dai, Hongying,
>Cc: r-help@r-project.org
>Subject: Re: [R] How to create arbitrary number of l
ng,
Cc: r-help@r-project.org
Subject: Re: [R] How to create arbitrary number of loops in R
On Thu, Mar 29, 2012 at 9:27 AM, ilai wrote:
Oops, sent to fast. A (maybe) clearer solution:
f <- function(x,m){
cmway <- combn(ncol(x),m)
xx <- x[,cmway]
dim(xx) <- c(nrow(x),nrow(cmway),ncol(c
On Thu, Mar 29, 2012 at 9:27 AM, ilai wrote:
Oops, sent to fast. A (maybe) clearer solution:
f <- function(x,m){
cmway <- combn(ncol(x),m)
xx <- x[,cmway]
dim(xx) <- c(nrow(x),nrow(cmway),ncol(cmway))
xx
}
f(M,3)
str(sapply(2:4,f,x=M))
And again lapply / apply , or even return icc(xx) in f
C
To cbind, you don't need a loop
(M <- matrix(1:50,nc=10))
c2way <- combn(ncol(M),2)
MM <- M[,c2way]
dim(MM) <- c(nrow(M),nrow(c2way),ncol(c2way))
MM
c3way <- combn(ncol(M),3)
MMM <- M[,c3way]
dim(MMM) <- c(nrow(M),nrow(c3way),ncol(c3way))
MMM
etc. etc.
Than you can (untested for icc) loop your
5 matches
Mail list logo