[R] Matrix/dataframe indexing
Guenther, Cameron
Cameron.Guenther at MyFWC.com
Mon Mar 5 18:49:35 CET 2007
Hi all,
I am hoping someone can help me out with this:
If I have dataframe of years and ages and the first column and first row
are filled with leading values:
Df<- age1 age2 age3
Yr1 1 0.4 0.16
Yr2 1.5 0 0
Yr3 0.9 0 0
Yr4 1 0 0
Yr5 1.2 0 0
Yr6 1.4 0 0
Yr7 0.8 0 0
Yr8 0.6 0 0
Yr9 1.1 0 0
Now the rest of the cells need to be filled according to the previous
year and age cell so arbitrarily, cell [2,2] should be value in cell
[1,1] * exp(0.3), and cell [2,3] should be the value in cell [1,2]*
exp(0.3), etc.
How do I write the for loop so that it will calculate the missing cell
values over both dimensions of the dataframe?
Thanks in advance
Cameron Guenther, Ph.D.
100 8th Ave. SE
St. Petersburg, Fl 33701
727-896-8626 ext. 4305
cameron.guenther at myfwc.com
More information about the R-help
mailing list