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,360 points
65 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,940 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 72 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
526 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,360 points
51 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
45 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
3,457 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,360 points
117 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,940 points
74 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
57 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,940 points
61 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,940 points
113 views