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
50 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 by Sophie may
• 9,870 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 54 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,170 points
169 views
0 votes
1 answer
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 in Data Analytics by anonymous
• 31,840 points
37 views
0 votes
2 answers
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
72 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,870 points
36 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 in Data Analytics by Zulaikha
• 870 points
28 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,870 points
48 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,870 points
72 views