Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to group data by names in two columns using R is by using the dplyr package. Assuming your data is stored in a data frame called df with two columns named Name1 and Name2, the following code can be used to group the data by the unique combinations of Name1 and Name2:

library(dplyr)

grouped_data <- df %>%
  group_by(Name1, Name2) %>%
  summarise(total = sum(Value))

This code will create a new data frame called grouped_data which contains the unique combinations of Name1 and Name2, along with the sum of the Value column for each group. You can replace Value in the summarise function with a different column name if your data contains a different numerical variable.