[R] Need Help - R Programming - Using iteration value to change field names for processing for every iteraion

Vijaya Kumar Regati VijayaKumar.Regati at m3bi.com
Tue May 30 09:02:52 CEST 2017


Hi,

I am new to R programming, I am trying to work on below requirement. But could not achieve desired result.
Appreciate if someone can help me on this :

test dataframe :
  Day1.balc Day2.balc Day3.balc Day4.balc
x       100        20        30        40
y       100        10        10        10
> class(test)
[1] "data.frame"

My Goal is to accomplish :
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 identified the line I have written inside the loop is not the correct one, can someone help me how I can use iteration value(i), for every iteration, as a basis for changing field names since field consists of 1,2,3... for each different day( Day1.balc Day2.balc Day3.balc Day4.balc etc.,).


Thanks,

Vijay



Disclaimer: IMPORTANT NOTICE: This e-mail (including any attachments) are confidential, may contain proprietary or privileged information and is intended for the named recipient(s) only. If you are not the intended recipient, any disclosures, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this email in error, please notify the sender by return e-mail or telephone immediately and permanently delete the message and any attachments.

	[[alternative HTML version deleted]]



More information about the R-help mailing list