[R] Data manipulation in columns (with apply?)
Bret Collier
bret at tamu.edu
Tue Oct 10 23:57:00 CEST 2006
R Users,
I have written a small simulation model in R which outputs a datafile consisting of ending population sizes for each simulation run (year). The data (see short data example below) is labeled by NUM (simulation run), sim (year) and N (yearly count). After searching the help files and coming up empty (probably because I used the wrong terms) I am appealing for some help for working with the output dataset.
What I want to do is for each of the i simulation runs (NUM) I want to
1) take N(t+1)/N(t)=lambda(t) for each year (where in the below example t=1,...,10--total years of the simulation)
2) Sum lambda(t) and divide by t (e.g., output both the mean/se of lambda for each simulation run)
3) Take the mean of the mean(lambda's) (and associated stddev, min, max) over all NUM
I think I have to write a function for use within an apply statement, but I am not quite there yet on the learning curve so most of my recent attempts in R have been useful learning experiences of what not to do...
Any suggestions/direction is greatly appreciated.
Bret Collier
TX A&M
NUM sim N
1 1 466
1 2 450
1 3 473
1 4 531
1 5 515
1 6 502
1 7 471
1 8 460
1 9 458
1 10 434
2 1 289
2 2 356
2 3 387
2 4 440
2 5 457
2 6 466
2 7 467
2 8 449
2 9 387
2 10 394
3 1 367
3 2 400
3 3 476
3 4 508
3 5 478
3 6 501
3 7 513
3 8 505
3 9 492
3 10 465
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 3.0
year 2006
month 04
day 24
svn rev 37909
language R
version.string Version 2.3.0 (2006-04-24) (yeah, I need to update)
More information about the R-help
mailing list