[R] Still avoiding loops

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Wed Jan 26 12:56:50 CET 2005


Please give a simple example of the input data and output that you
desire. It is difficult to understand from you partial codes what you
mean. For example what is Y ?

Are you trying to find add values from pairs of rows ? If so, please see
my posting "pairwise difference operator" where I wanted to find the
differences between pairs of columns. 
http://tolstoy.newcastle.edu.au/R/help/04/07/1633.html

Otherwise, please send a sample input and output. Thank you.

Regards, Adai


On Wed, 2005-01-26 at 11:40 +0400, Jacques VESLOT wrote:
> Dear all,
> 
> I have a matrix X with 47 lines and say 500 columns - values are in {0,1}.
> I'd like to compare lines.
> 
> For that, I first did:
> 
> for (i in 1:(dim(X)[1]-1))
> for (j in (i+1):dim(X)[1]) {
> 	Y <- X[i,]+Y[j,]
> 	etc.
> 
> but, since it takes a long time, I would prefer avoding loops;
> for that, my first idea was to add this matrix:
> 
> X1=X[,rep(1:46,46:1)]
> 
> to this one:
> 
> res=NULL
> for (i in (2:47)) res=c(res,i:47)
> 
> X2=X[,res]
> 
> (Is it a nice alternative way ?)
> Is there a way to create the second matrix X2 without a loop, such as for X1
> ?
> 
> Thanks in advance,
> 
> Jacques VESLOT
> 
> ______________________________________________
> R-help at 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
>




More information about the R-help mailing list