I have the following database as an example and the result I expect:
In case the values in the new dataframe refer to the days, which is the difference of the last date of a category from the first of the same category.
You can do whatever you want with the base R function aggregate
.
Grupo <- c("A", "A", "A", "B", "B", "C", "C")
Data <- c("01/02/2017", "15/02/2017", "20/03/2017", "18/02/2017", "01/03/2017", "15/02/2017", "20/02/2017")
dados <- data.frame(Grupo, Data)
dados$Data <- as.Date(dados$Data, "%d/%m/%Y")
result <- aggregate(Data ~ Grupo, dados, function(d) d[length(d)] - d[1])
result
# Grupo Data
#1 A 47
#2 B 11
#3 C 5