Use ave
:
df$sumx1 <- ave(df$x1, df$key, FUN=sum)
More Related Contents:
- Is there a dplyr equivalent to data.table::rleid?
- Replace NA with previous or next value, by group, using dplyr
- ggplot2 – bar plot with both stack and dodge
- Assign multiple columns using := in data.table, by group
- Using the rJava package on Win7 64 bit with R
- `levels
- Subset with unique cases, based on multiple columns
- What are the R sorting rules of character vectors?
- Avoid ggplot sorting the x-axis while plotting geom_bar()
- How do you draw a line across a multiple-figure environment in R?
- Set margin size when converting from Markdown to PDF with pandoc
- Change row order in a matrix/dataframe
- Convert summary to data.frame
- how to pivot/unpivot (cast/melt) data frame? [duplicate]
- Calculate group mean while excluding current observation using dplyr
- What are the performance differences between for-loops and the apply family of functions?
- Emulate split() with dplyr group_by: return a list of data frames
- Subsetting data.table using variables with same name as column
- Most frequent value (mode) by group [duplicate]
- r igraph find all cycles
- How to read csv file in R where some values contain the percent symbol (%)
- How does one change the levels of a factor column in a data.table
- When should I use setDT() instead of data.table() to create a data.table?
- Remove duplicates based on 2nd column condition
- Reusing a Model Built in R
- Undefined columns selected when subsetting data frame
- Generate all possible permutations (or n-tuples)
- devtools::install_github() – Ignore SSL cert verification failure
- fast large matrix multiplication in R
- When does the argument go inside or outside aes()?