-1
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
Welcome to Stackoverflow! Take a look at how to improve your next questions.
– Tomás Barcellos