[R] Subtraction loop

From: <ecvetano_at_uwaterloo.ca>
Date: Mon, 28 Jun 2010 11:22:43 -0400


I have a data frame with 2 columns, one for day and one for average. The day starts at 97 all the way to 279. I want to subtract day 98 average- day 97 average, then day99 average -day 98 average and so on down my list, creating another column with the subtracted results. I have:

     Day DailyAverage

1    97    0.6076782
2    98    0.7121478
3    99    0.8059347
4   100    0.9545806
5   101    1.0589791
6   102    1.1335981
7   103    1.2676922
8   104    1.4429847
9   105    1.6477266
10  106    1.7970784

etc. with values to day 279

I'm guessing I need to create some kind of loop for this, but I am unsure as to how to do this. Any help is greatly appreciated.

Thanks,
Emilija



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 Mon 28 Jun 2010 - 15:25:05 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 Mon 28 Jun 2010 - 15:50:42 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