06 October 2019
input_Principal <- 1000
input_Interest <- 10 #Percentage entered as integer
Interest_df <- NULL #Set a blank data frame
for (i in 1:10) { #Run a loop for 10 years
input_Principal <- input_Principal*(1+input_Interest/100) #Formula: P*(1+R/100)^n (used For loop for 'n')
Interest_df <- rbind(Interest_df, input_Principal-1000) #Y-O-Y amount less initial principal
}
Interest_df <- as.data.frame(Interest_df)
Interest_df <- cbind(Interest_df, 1:10) #Fuse years from 1 to 10 with Compound Interest column
names(Interest_df) <- c("Compound Interest", "Year Number")
Interest_df
## Compound Interest Year Number ## 1 100.0000 1 ## 2 210.0000 2 ## 3 331.0000 3 ## 4 464.1000 4 ## 5 610.5100 5 ## 6 771.5610 6 ## 7 948.7171 7 ## 8 1143.5888 8 ## 9 1357.9477 9 ## 10 1593.7425 10