Subsetting a dataframe based on daily maxima

后端 未结 4 425
遥遥无期
遥遥无期 2021-01-27 05:15

I have an excel csv with a date/time column and a value associated with that date/time. I\'m trying to write a script that will go through this format (see below), and find 1) t

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-27 06:00

    For another alternative, you could use data.table:

    dat_table <- data.table(dat)
    
    dat_table [ , list(is_max = V3==max(V3), V2, V3), by= 'V1'][which(is_max),][,is_max :=NULL]
    

    EDIT as per @MattDowle's comment

    dat_table[, .SD[which.max(V3)], by=V1]
    

    For an even simpler data.table solution.

提交回复
热议问题