Hello,

Try

x <- matrix(1:18, ncol = 6)
sapply(seq_len(ncol(x)), function(i) x[, i] - rowMeans(x[, -i]))


Hope this helps,

Rui Barradas
Em 27-11-2012 17:51, eliza botto escreveu:
Dear UseRs,Extremely sorry for a basic question. I have a matrix of 19 rows and 365 
columns. what i want to do is the following...First i want to leave out column number 1 
and want to calculate the row wise mean of the remaining columns, which will obviously 
give me 365 values in one column, and then subtracting these values from the column i 
left out i.e. col=1 then i want to leave out column 2 and calculate the row wise mean of 
the remaining columns which includes column 1 too and then subtracting these values from 
the column i left out i.e. col=2.and then continuing this process the last column. i know 
a kind of "manual way" of doing things but its extremely long and laborious.Is 
there any loop command or shorter way??
thanks in advanceregardseliza                                   
        [[alternative HTML version deleted]]

______________________________________________
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.

______________________________________________
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