It’s hard to describe what I mean, I mean I have the following data frame
A 1013574 1014475
A 1014005 1014475
A 1014005 1014435
I want to merge these data into A 1013574 1014475
,Is there any function that can do me achieve this goal?
CodePudding user response:
This is an updated answer. I think that this is what you want. I added additional rows, so you can see how it works with multiple data.
library(dplyr)
df <- tibble(a = c("A", "A", "A","B", "B", "B" ),
v1 = as.numeric(c(1013574,1014005,1014005, 1014005, 1014305, 1044005)),
v2 = as.numeric(c(1014475, 1014475,1014435, 1014435, 1014435, 1314435)))
df_new <-df %>% group_by(a) %>% mutate(v1 = min(v1),
v2 = max(v2)) %>%
distinct()