unable to perform calculations using r data.table package

后端 未结 2 1325
南方客
南方客 2021-01-12 01:22

I have a huge data frame, last 30 rows are below:

libary(data.table)

dput(p)

structure(list(DATE = structure(c(1367516015,          


        
相关标签:
2条回答
  • 2021-01-12 01:57

    The problem is that your ifelse statement returns integer type for some values and numeric (double) for some other entries. And data.table complains about the mismatch in the column type as it expects the coercion to be performed by the user (for performance reasons as given in the error). So, just wrap it around with as.numeric so that all values will be converted to double.

    p <- p[,RELATIVE_PERCENT := as.numeric(ifelse(ENT_PCT>100, (USED_CORES/ENT)*100, 
                          USR_SYS_CPU_PCT)), by= c("DATE", "LPAR")]
    
    0 讨论(0)
  • 2021-01-12 02:13

    I did this:

    sapply(p, class)
    

    and noticed that one of my columns was integer. Then I did this:

    x<-x[,RELATIVE_PERCENT:=ifelse(ENT_PCT>100, ((USED_CORES/ENT)*100), as.numeric(USR_SYS_CPU_PCT)), by= c("DATE", "LPAR")]
    

    and it is money

    0 讨论(0)
提交回复
热议问题