I have a dataframe
df <- data.frame(Name = c("Terry", "Bob", "Jerry"),
ContractsSold = c(30,40,50), agentsHired = c(10,12, 14),
Sales = c(3500,4000, 5000),
stringsAsFactors = FALSE)
I also have a list of values: e.g.
days = seq(0,20,5)
I have a for loop that takes each row e.g. Terry, 30, 10, 3500 and for each value performs a function that is currently working, outputs the total Revenue based off of that calculation and outputs it in this format.
days Name Revenue
0 Terry 10000
1 Terry 10000
2 Terry 10300
3 Terry 19000
4 Terry 14000
5 Terry 10090
....
20 Terry 10000
0 Bob 20000
...
20 Bob 20000
And so on. I want to get this as my output:
days Terry Bob Jerry
0 10000 20000 .....
1 10000 ....
2 13000
3 (the revenues calculated)
....
20
I currently have this as my code: and it produces the first output.
for (j in seq_len(nrow(df))) for (d in days) {
totalRevenue <- (function is here and working)
return(new_df)
}
Could someone please help me with how in my for loop I can store each name as a column with each of their corresponding revenues depending on what day it is in the "days" column? Thank you!