Re: [R] Apply a function to columns of a matrix

2012-09-08 Thread arun
t.org" Cc: Sent: Saturday, September 8, 2012 3:45 PM Subject: [R] Apply a function to columns of a matrix Dear All,   as a follow up to my previous e-mail (I think I am getting closer...):   I am trying to apply the trapezoidal functions to a matric column by column. I have the following

Re: [R] Apply a function to columns of a matrix

2012-09-08 Thread arun
- From: Andras Farkas To: "r-help@r-project.org" Cc: Sent: Saturday, September 8, 2012 3:45 PM Subject: [R] Apply a function to columns of a matrix Dear All,   as a follow up to my previous e-mail (I think I am getting closer...):   I am trying to apply the trapezoidal functions to a matric

Re: [R] Apply a function to columns of a matrix

2012-09-08 Thread jim holtman
Is this what you wanted? You had two arguments to your function, but only supplying one via the 'apply'. Also your argument names were the same as your variables which was confusing. > a <-matrix(c(1:100),ncol=10) > b <-matrix(c(2,4,6,8,10,12,14,16,18,20)) > > apply(a,2,function(y,x) sum(diff(x)

[R] Apply a function to columns of a matrix

2012-09-08 Thread Andras Farkas
Dear All,   as a follow up to my previous e-mail (I think I am getting closer...):   I am trying to apply the trapezoidal functions to a matric column by column. I have the following code:   a <-matrix(c(1:100),ncol=10) b <-matrix(c(2,4,6,8,10,12,14,16,18,20))   apply(a,2,function(b,a) sum(diff(b)