This is for using aggregate function in R at two levels. For the below data frame,
df <- data.frame( Event = c('A1','A1','A1','A1','A1'),
Time = c(10,11,21,17,12),
Type = c('New','New','Repeat','Repeat','Repeat'))
At one level, the following is working perfectly
aggregate(df$Time,
by=list(df$Event),
FUN = function(x) c(mintime = min(x),endtime = max(x)))
I am looking for the count of each Type with a condition check.
## CODE NOT WORKING
aggregate(df,by=list(df$Event),
FUN = function(x) c(mintime = min(df$time),endtime = max(df$time), New=length(df$time=='New'),Repeat=length(df$time=='Repeat')))
so that I will get
Group.1 x.mintime x.maxtime x.New x.Repeat
A1 10 21 2 3