-1
$\begingroup$

I want to update this Remaining column in this table below: enter image description here

How do I do this in R programming?

I tried

while (n.Remaining>0)

{ n.remaining <- n.total-n.expense}

Desired Output:

enter image description here

$\endgroup$
0
$\begingroup$

in R you just need to do 10-cumsum(expense). This will give you the Remaining column

| improve this answer | |
$\endgroup$
0
$\begingroup$

More complicated than a cumsum, but for loop could look something like:

for (j in 3:5){
       n[j,'Remaining'] <- n[j-1,'Remaining'] - n[j,'expense']}

If your answer needs to be strictly positive, think about including a while or if statement.

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.