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, 2019 in Data Analytics by Tyrion anex
• 8,320 points
58 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 25, 2019 by Sophie may
• 9,900 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 65 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,290 points
356 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 29, 2019 in Data Analytics by Tyrion anex
• 8,320 points
43 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 27, 2019 in Data Analytics by anonymous
• 32,440 points
41 views
0 votes
2 answers

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

You are getting this error since the ...READ MORE

answered Aug 16, 2019 in Data Analytics by anonymous
• 32,440 points
1,170 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, 2019 in Data Analytics by Tyrion anex
• 8,320 points
91 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, 2019 in Data Analytics by Sophie may
• 9,900 points
49 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
• 890 points
42 views
0 votes
1 answer

Data segmentation using R programming

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

answered Jan 4, 2019 in Data Analytics by Sophie may
• 9,900 points
49 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
• 9,900 points
87 views