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 get icc value vector. Under the array 
format, how can I extract icc value from the array output and turn it into a 
vector?

#ilai's code:
library(irr)
M <- matrix(1:50,nc=10)
c2way <- combn(ncol(M),2)
MM <- M[,c2way]
dim(MM) <- c(nrow(M),nrow(c2way),ncol(c2way))
MM
A<-apply(MM,3,icc)  #How can I combine A[[1]]$value, A[[2]]$value, ... into a 
vector?

#Christian's code:
library(irr)
M <- matrix(1:50,nc=10)
combn(10, 2, function(v) icc(M[,v])) #How can I get all values in row 7 as a 
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 loops in R

On Thu, Mar 29, 2012 at 9:27 AM, ilai <ke...@math.montana.edu> 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

Cheers


Electronic mail from Children's Mercy Hospitals and Clinics. This communication 
is intended only for the use of the addressee. It may contain information that 
is privileged or confidential under applicable law. If you are not the intended 
recipient or the agent of the recipient, you are hereby notified that any 
dissemination, copy or disclosure of this communication is strictly prohibited. 
If you have received this communication in error, please immediately forward 
the message to Children's Mercy Hospital’s Information Security Officer via 
return electronic mail at informationsecurityoffi...@cmh.edu and expunge this 
communication without making any copies. Thank you for your cooperation.
______________________________________________
R-help@r-project.org 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.

Reply via email to