Subtracting times that exceed 60 minutes

后端 未结 3 911
忘了有多久
忘了有多久 2021-01-24 01:41

I have a dataset which contains the timing of events in football. A game exceeds 60 minutes, and I\'m trying to calculate intervals. This is the data I have:

dat         


        
3条回答
  •  执念已碎
    2021-01-24 01:49

    This might work too

    data1 <- c("11:14", "17:27", "25:34", "39:17", "39:59", "42:32", "50:15", "50:53", "64:22", "67:39")
    data2 = sapply(strsplit(data1,":"), # from http://stackoverflow.com/a/5187350/7128934
                   function(x) {
                       x <- as.numeric(x)
                       x[1]+x[2]/60
                   }
    )
    
    difference = list()
    for (i in 1: (length(data1) - 1))  {
    difference[i] = data2[i+1] - data2[i]
    }
    

提交回复
热议问题