Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Spreadsheet-like calculation in R with a growth component

$
0
0

I have a spreadsheet calculation that I want to transfer into R. I have a few columns and rows that I am trying to do some simple arithmetic on, and a couple of ifelse.

See image

The short question is:

  • How do I represent this data in one (or more) meaningful object(s)?
  • How do I repeat this data over n years, with a growth factor for two of the columns?

Preferably with short and elegant code.

More details:

Problem 1 - how to represent columns and rows. Should I use use dataframe, table, vector, matrix, or whatever? The idea was to have an object representing every column. For example to arrive at CF, I would want something representing column E and something representing S, and do E+S to arrive at CF, and then do sum(CF).

Problem 2 - this represents one year. I would like to repeat the same "dataframe" over t years with a negative yearly growth n for iso and positive growth p for St. This is where things get complicated and I lose track.

The red cell is a cash flow. Once I have, say 15 years, of cash flows, I could match them against the initial investment and get the internal rate of return.

(For the sake of the example just consider all columns as fixed numbers)

I have tried brute forcing with for-loops, but I ran into lots of strange stuff, and never really got far.

Does someone have any good ideas?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>