R Programming: Using iteration value to change field names

0 votes

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.

Mar 25 in Data Analytics by Tyrion anex
• 8,280 points
27 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Remove the first and last column from the test dataset and combine the datasets together:

Days <- test[-1] + test[-ncol(test)]
answered Mar 25 by Sophie may
• 9,090 points

Related Questions In Data Analytics

0 votes
1 answer

Is it possible to change the column names of the dataset that I'm using in R?

That is definitely possible in R. You ...READ MORE

answered Dec 17, 2018 in Data Analytics by Anisha

edited Dec 17, 2018 20 views
0 votes
1 answer

How to change y axis max in time series using R?

The axis limits are being set using ...READ MORE

answered Apr 3, 2018 in Data Analytics by darklord
• 6,140 points
42 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$symb ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,280 points
47 views
0 votes
1 answer

Parallel programming In R using GPU

Check out the CRAN Task View on High-Performance ...READ MORE

answered Feb 4 in Data Analytics by Tyrion anex
• 8,280 points
43 views
0 votes
1 answer

R programming: Naming the output file using a variable

Use the paste command: write.csv(max.hsi, paste0("Index_", i,".csv" ...READ MORE

answered Mar 25 in Data Analytics by Sophie may
• 9,090 points
7 views
0 votes
1 answer

Changing variable values using R programming

This should work: df$symbol <- as.character(df$symbol) df$symbol[df$symbol == "ABCD.BO"] ...READ MORE

answered 7 hours ago in Data Analytics by Zulaikha
• 240 points
2 views
0 votes
1 answer

Data segmentation using R programming

I tried solving your problem, try the ...READ MORE

answered Jan 4 in Data Analytics by Sophie may
• 9,090 points
29 views
0 votes
1 answer

Using CMD Windows to execute R language

So, Command line arguments can't be directly ...READ MORE

answered Jan 14 in Data Analytics by Sophie may
• 9,090 points
44 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.