median between matrix column
m<-matrix(1:10,ncol=5)
m
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10
apply(m,2,function(x){median(x,m[,5])})
[1] 5.5 6.5 7.5 8.5 9.5
Though i am not 100% sure thats what you mean. But the median of each row between two columns kind of doesn't make much sense to me, its only 2 values then after all.
On 15.10.2012, at 14:20, eliza botto wrote:
Dear useRs, 1. how to calculate single median value for two columns of a matrix? 2. i have a matrix of 16 columns and 365 rows, how to calculate median between columns 1 and 16, 2 and 16, 3 and 16, 4 and 16, 5 and 16 till 15th column. is there a loop command to do the said operation? 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.