Your fields are adjacent, right? If so, you do not need to refer to them by name to accomplish this. Please spend some (more) time with an R tutorial or two as Rolf suggested, especially with "indexing".
-- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, May 30, 2017 at 3:07 AM, Vijaya Kumar Regati <vijayakumar.reg...@m3bi.com> wrote: > Hi All, > > > I have tried in different ways. > > Finally I got the solution this way : > > > for(i in 2:4) { > test[,paste0("Day",i,".Prod.balc")] <- test[,paste0("Day",i,".Prod.balc")] > + test[,paste0("Day",i-1,".Prod.balc")] > } > > > Please save it for references, if needed in future. > Thanks all for your references. > > > List Moderator, > > You can mark the question as closed now. > > > > With Regards, > Vijaya Kumar Regati > Technical Lead, M3bi India Private Ltd > Work: 040-67064732 > > > ________________________________ > From: Vijaya Kumar Regati > Sent: Tuesday, May 30, 2017 3:35 PM > To: Jim Lemon > Subject: Re: [R] Need Help - R Programming - Using iteration value to change > field names for processing for every iteraion > > > Thank you for the response. > > That did not give me desired output when ran. > > > But I was able to find 1 solution : > > > for(i in 2:4) { > test[,paste0("Day",i,".Prod.balc")] <- test[,paste0("Day",i,".Prod.balc")] > + test[,paste0("Day",i-1,".Prod.balc")] > } > > Its working now. > > > With Regards, > Vijaya Kumar Regati > Technical Lead, M3bi India Private Ltd > Work: 040-67064732 > > ________________________________ > From: Jim Lemon <drjimle...@gmail.com> > Sent: Tuesday, May 30, 2017 3:00:39 PM > To: Vijaya Kumar Regati > Subject: Re: [R] Need Help - R Programming - Using iteration value to change > field names for processing for every iteraion > > Hi Vijaya, > How about: > > test_dataframe<-read.table( > text="Day1.balc Day2.balc Day3.balc Day4.balc > 100 20 30 40 > 100 10 10 10", > header=TRUE) > t(apply(test_dataframe,1,cumsum)) > > Jim > > On Tue, May 30, 2017 at 5:02 PM, Vijaya Kumar Regati > <vijayakumar.reg...@m3bi.com> wrote: >> 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]] >> >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help > R-help Info Page - Homepage - SfS – Seminar for > Statistics<https://stat.ethz.ch/mailman/listinfo/r-help> > stat.ethz.ch > The main R mailing list, for announcements about the development of R and the > availability of new code, questions and answers about problems and solutions > using R ... > > >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > 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]] > > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.