How to add a row in a existent table?

13 views
Skip to first unread message

Iasmim Louriene

unread,
Oct 24, 2016, 7:31:03 PM10/24/16
to Shiny - Web Framework for R
Hello all,

I'm trying to add a row that contains the sum of trees2 (nt) and the name "Total" in a existent summary table. Does anyone know how to do that? I really appreciate the help!
Here's my server.R

output$sumy <- renderTable({

input$action

if(is.null(input$action))
return(NULL)

else

Arvsumy <- isolate({

trees2 <- FindTreesCHM(fchm(), (as.numeric(input$fws)), (as.numeric(input$minht)))

h <- trees2["height"]
nt <- nrow(trees2)
cbind(summary(h))
})

})

Thanks a lot!

Bárbara Borges

unread,
Oct 26, 2016, 6:10:08 AM10/26/16
to Shiny - Web Framework for R
I'm gonna use the `cars` dataset here, but it should work for you too. From what I understand you have something like:

h <- cars[["speed"]]
nt <- nrow(cars)
tab <-  cbind(summary(h))

Now, to add another row with the `nt` variable, you could do:

tab <- rbind(tab, nt)

You will notice that the name for that last row is now `nt`. You could either change it "manually" (i.e. `rownames(tab)[nrow(tab)] <- "Total"`) or you can have `Total <- nrow(cars)` from the beginning.

Hope it works!
Barbara
Reply all
Reply to author
Forward
0 new messages