Edit to Include vectors
BaseSal <- c(22745,23606,24761,25873,27097,28533,30153,31813,
33588,35492,37524,39630,41935,44346,46855,49483,
52260,55222,58211,61194,64441,67900,71493,75299,
79455,83641,88169,92811,97673,102780,108257,114015,
120216,126620,133184,139879,147219,137346);
AnnualInc <- c(678,703,730,762,815,843,876,907,939,981,1045,1081,
1125,1201,1245,1293,1355,1327,1382,1440,1503,1566,
1631,1694,1766,1838,1935,2010,2088,2164,2245,2321,
2397,2480,2560,2648,2731,1);
My following code has Vector BaseSal with the Base Salary for 38 different positions, as well as Vector AnnualInc which is the annual amount the Base Salary increases for each of the 38 positions. This code works perfectly:
for (i in 1:38)
print(BaseSal[i]+(AnnualInc[i] * 0:10));
The reason for the rang 0:10 is 0 is the first year salary, and the annual increment is added each year for 10 years.
And I was actually surprised at how little I had to do to get there. I have read a bit about apply being better for use in R, and I have it partially working in apply. The results I get deliver me the value of if the first years annual increase was applied to the base salary. Here is the code I'm using to get there :
l<-matrix(BaseSal,38,11,FALSE);
apply(l,2,function(z) z+(AnnualInc));
Can anyone help me figure out how to iterate through each years increment using a matrix and apply, including leaving the first year as just the base salary?