Wrong units displayed in data.table with POSIXct arithmetic

前端 未结 3 723
后悔当初
后悔当初 2021-01-20 16:35

When durations are computed in data.table (v1.9.2), the wrong units can be printed with POSIXct arithmetic. It seems the first units are chosen.

require(\"da         


        
3条回答
  •  情歌与酒
    2021-01-20 17:35

    This could be viewed as operator error, because your table is (automatically) displaying a numeric equivalent of a difftime, but you are not specifying which units to display the answer in. In most cases where you wish to export/display difftime values the desired units should be specified in an explicit conversion to numeric. E.g.

    dt[ , as.numeric( max(time) - min(time), units="hours" ), by=id]
    

提交回复
热议问题