[R] loop for column substraction of a matrix

Rui Barradas ruipbarradas at sapo.pt
Fri Oct 5 22:55:47 CEST 2012


1. Let me refrase it a bit. For each column, sum all others and take the 

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-10-2012 21:05, eliza botto escreveu:
> 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
> eliza
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help at 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.

More information about the R-help mailing list