I have this sample data:
cvar <- c("2015-11-01","2015-11-02","All")
nvar1 <- c(12,10,5)
nvar2 <- c(7,5,6)
data <- cbind.data.frame(cvar,nvar1,nvar2)
And I just want to add a new row to the data.frame containing the sums of nvar1 & nvar2 and a character, so with base R I would just use
data[nrow(data)+1,] <- c("add",sum(data[,2]),sum(data[,3]))
or something more clever with lapply, but just to show you what I'm looking for.
I would like this simple command within the pipe environment, so data %>% ... gives me the above outcome.
Appreciate any help, thank you.
data.tablehere.data.tableis a different package. TO convert todata.table, it should bedata.table(cvar, ....)If you are usingdplyr, then try withbindrowstbl_df