[R] sequentially aggregating elements of a vector

Martin Batholdy batholdy at googlemail.com
Mon Oct 14 21:16:41 CEST 2013


> The last element 11 in y is confusing.

sorry for the typo.
It is of course y <- c(1,3,6,10)


> cumsum(x)

thanks!


On Oct 14, 2013, at 20:57 , arun <smartpink111 at yahoo.com> wrote:

> The last element 11 in y is confusing.
> 
> cumsum(x)
> [1]  1  3  6 10
> A.K.
> 
> 
> On Monday, October 14, 2013 2:51 PM, Martin Batholdy <batholdy at googlemail.com> wrote:
> Hi,
> 
> for labelling the stacked bars in a barplot, I need to sequentially sum up the elements of a vector.
> 
> 
> Suppose I have;
> 
> x <- c(1,2,3,4)
> 
> (which correspond to the bar-width of stacked bars)
> 
> I need;
> 
> y <- c(1,3,6,11)
> 
> 
> (which corresponds to the upper y-values for each bar).
> 
> 
> 
> 
> What is the easiest way in R to get from x to y?
> (Or more general; to add labels inside the bars in a stacked barplot)
> 
> 
> 
> thanks!
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 



More information about the R-help mailing list