R Programming Using iteration value to change field names

+1 vote

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 26, 2019 in Data Analytics by Tyrion anex
• 8,700 points
802 views

1 answer to this question.

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 26, 2019 by Sophie may
• 10,620 points

Related Questions In Data Analytics

+1 vote
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 1,717 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 Sahiti
• 6,370 points
3,832 views
0 votes
1 answer

R programming: Using Caret package to implement Random Forest

You can check out the official docs ...READ MORE

answered Apr 30, 2019 in Data Analytics by Tyrion anex
• 8,700 points
708 views
0 votes
1 answer

How to change the datatype of any field in an external dataset in R?

Hi Anand, Try as below - class(dataset/dataframe$col_name) <- ...READ MORE

answered Jun 28, 2019 in Data Analytics by anonymous
• 33,030 points
765 views
+1 vote
3 answers

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$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,824 views
+1 vote
1 answer

Parallel programming In R using GPU

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

answered Feb 4, 2019 in Data Analytics by Tyrion anex
• 8,700 points
1,398 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 26, 2019 in Data Analytics by Sophie may
• 10,620 points
6,520 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 May 27, 2019 in Data Analytics by Zulaikha
• 910 points
921 views
0 votes
1 answer

Data segmentation using R programming

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

answered Jan 5, 2019 in Data Analytics by Sophie may
• 10,620 points
681 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, 2019 in Data Analytics by Sophie may
• 10,620 points
1,146 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP