Group rows in data frame based on time difference between consecutive rows

后端 未结 2 1170
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 22:50

I have a data frame of this type

YEAR   MONTH  DAY  HOUR       LON      LAT

1860     10      3   13      -19.50   3.00          
1860     10      3   17             


        
2条回答
  •  囚心锁ツ
    2020-12-06 23:16

    I would try something along these lines. Since you mention that you only need to figure out the subsetting logic, I haven't bothered to add the correlation coeff calculation.

    df$date <- as.Date(paste(df$YEAR,df$MONTH,df$DAY),'%Y %m %d')
    
    uniquedates <- unique(df$date)
    uniquedatesfourth <- uniquedates + 4
    
    for ( i in seq(length(uniquedates)))
    {
       tempsubset <- subset(df, date >= uniquedates[i] & date >= uniquedatesfourth[i])
       # operations on tempsubset
    }
    

提交回复
热议问题