[R] help with loop

From: Rafael Moral <rafa_moral2004_at_yahoo.com.br>
Date: Thu, 12 Mar 2009 06:04:29 -0700 (PDT)


Dear useRs,
I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column.

So, I wrote something like this:

  c <- list()
  for(i in 1:ncol(mydata)) {
  for(j in 2:nrow(mydata)) {
  c[[i]] <- sum(yc[j,i] - yc[(j-1),i])
  }}}

As for the columns it works pretty fine, but it only returns the last subtraction, however, I need the sum of all subtractions.

Any ideas?

Regards,
Rafael.

      Veja quais são os assuntos do momento no Yahoo! +Buscados

        [[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. Received on Thu 12 Mar 2009 - 12:09:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 Mar 2009 - 13:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive