[R] loop for column substraction of a matrix

arun smartpink111 at yahoo.com
Fri Oct 5 22:57:09 CEST 2012


Try this:
for(i in 1:ncol(mat1)){
 list1[[i]]<-t(apply(mat1,1,function(x) x[i]-x))


----- Original Message -----
From: eliza botto <eliza_botto at hotmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Sent: Friday, October 5, 2012 4:05 PM
Subject: [R] loop for column substraction of a matrix

Dear useRs,

I have a matrix with 38 columns and 365 rows. what i want to do is the following.....

1. subtracting from each column, first itself and then all the remaining columns. More precisely, from column number 1, i will first subtract itself(column 1) and then the remaining 37 columns. Afterwards i will take column number 2 and do the same. In this way i want to proceed till 38th column. 
2. i want to print the resulting matrix on A4 paper.

Bundle of thanks in advance.

best regards

    [[alternative HTML version deleted]]

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list