I have a vector of values -1, 0, 1, say
a - c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1)
I want to create a vector of the cumulative sum of this, but I need to set a
maximum and minimum value for the cumsum, for example:
max_value - 2
min_value - -2
the expected result would be (0, 1,
Try this:
ac - cumsum(a)
ifelse(ac 2, max_value, ifelse(ac -2, min_value, ac))
On Thu, Nov 25, 2010 at 6:44 PM, henrique henri...@allianceasset.com.brwrote:
I have a vector of values -1, 0, 1, say
a - c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1)
I want to create a vector of the
On Thu, Nov 25, 2010 at 3:44 PM, henrique henri...@allianceasset.com.br wrote:
I have a vector of values -1, 0, 1, say
a - c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1)
I want to create a vector of the cumulative sum of this, but I need to set a
maximum and minimum value for the cumsum, for
Does this do it;
pmin(2, pmax(-2, cumsum(a)))
[1] 0 1 1 2 2 2 1 0 0 -1 -2
On Thu, Nov 25, 2010 at 3:44 PM, henrique henri...@allianceasset.com.br wrote:
I have a vector of values -1, 0, 1, say
a - c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1)
I want to create a vector of the
4 matches
Mail list logo