Or, using your mapply solution, compute
rs <- rowSums(mat1)
and then use it for all subtractions. With a larger dataset this would
be probably faster.
Rui Barradas
Em 05-10-2012 22:41, arun escreveu:
Hi,
Sorry, I think I misunderstand your question (after reading Rui's solution).
You can a
Dear Arun and Barradas,
millions of thanks. you guys always rock.
regards
eliza
> Date: Fri, 5 Oct 2012 14:41:38 -0700
> From: smartpink...@yahoo.com
> Subject: Re: [R] loop for column substraction of a matrix
> To: eliza_bo...@hotmail.com
> CC: ruipbarra...@sapo.pt; r-help@r-proj
Hi,
Sorry, I think I misunderstand your question (after reading Rui's solution).
You can also try any of these to get the result if this is what you meant:
set.seed(1)
mat1<-matrix(sample(1:500,380,replace=TRUE),ncol=38)
res1<-t(do.call(rbind,lapply(1:ncol(mat1), function(i)
mat1[,i]-apply(mat1,
HI,
Try this:
set.seed(1)
mat1<-matrix(sample(1:500,380,replace=TRUE),ncol=38)
list1<-list()
for(i in 1:ncol(mat1)){
list1[[i]]<-t(apply(mat1,1,function(x) x[i]-x))
list1}
list1
A.K.
- Original Message -
From: eliza botto
To: "r-help@r-project.org"
Cc:
Sent: Friday, October 5, 20
Hello,
1. Let me refrase it a bit. For each column, sum all others and take the
symmetric.
mat <- matrix(1:30, ncol = 3)
sapply(seq_len(ncol(mat)), function(i) -rowSums(mat[, -i]))
2. write.table (maybe using sep = "\t" ?) and send the file to printer.
Hope this helps,
Rui Barradas
Em 05
5 matches
Mail list logo