sum of values for multiple rows with same name in r : <p>how to perform a sum of values for multiple rows with the same name in r and render a chart in plotly.i have tried a couple of methods like aggregate and tapply, none of them seems to be working for me, could anyone tell me where I am going wrong. </p>

<pre><code>library(dplyr)
    #&gt; 
    #&gt; Attaching package: 'dplyr'
    #&gt; The following objects are masked from 'package:stats':
    #&gt; 
    #&gt;     filter, lag
    #&gt; The following objects are masked from 'package:base':
    #&gt; 
    #&gt;     intersect, setdiff, setequal, union
    library(shiny)
    library(plotly)
    #&gt; Loading required package: ggplot2
    #&gt; 
    #&gt; Attaching package: 'plotly'
    #&gt; The following object is masked from 'package:ggplot2':
    #&gt; 
    #&gt;     last_plot
    #&gt; The following object is masked from 'package:stats':
    #&gt; 
    #&gt;     filter
    #&gt; The following object is masked from 'package:graphics':
    #&gt; 
    #&gt;     layout
    cdata1&lt;-data.frame(stringsAsFactors=FALSE,
                     names = c("a", "a", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b",
                               "b", "c", "c", "c", "d", "d", "d"),
                     values = c(12, 32, 43, 45, 21, 21, 21, 32, 43, 54, 65, 76, 87, 80, 78,
                                68, 68, 67, 57)
    )

    ui&lt;-fluidPage(fluidRow(plotlyOutput("id1")),
                  fluidRow(plotlyOutput("id2"))
    )



    server&lt;-function(input,output){

      output$id1&lt;-renderPlotly({

        # a&lt;-aggregate(cdata1$X2014,by=list(cdata1$States.UTs),FUN=sum)
        # plot_ly(cdata1,x=cdata1$States.UTs,y=cdata1$X2014)
        cdata1 %&gt;%
          group_by(grp = rleid(cdata1$names)) %&gt;% 
          summarise(names = first(cdata1$names), 
                    values = sum(cdata1$values)) %&gt;%
          ungroup %&gt;%
          select(-grp)
        plot_ly(cdata1,x=cdata1$names,y=cdata1$values)
      })

    }
    shinyApp(ui,server)
</code></pre>
