I am new to R programming, this is my test data frame :
Day1.balc Day2.balc Day3.balc Day4.balc
x 100 20 30 40
y 100 10 10 10
> class(test)
[1] "data.frame"
I want to accomplish the following:
Day2.balc <- Day2.balc + Day1.balc
Day3.balc <- Day3.balc + Day2.balc
.
.
.
Day30.balc <- Day30.balc + Day29.balc
# Testing for first 4 days
for (i in 1:4 ) {
test$Day[i].balc <- test$Day[i].balc + test$Day[i-1].balc
}
I'm not sure if my code is right, any help would be appreciated.