Warning message with melt.data.table

How to attend this alert?
Reading the help, I can't figure out what to do!
Is it possible that you have inconsistent results for it?

Warning message:
In melt.data.table(dtODU[, .SD, .SDcols = is.numeric], id.vars = c(1)) :
  'measure.vars' [TargetFreq, ActualFreq, OAT, HST, ...] are not all of the same type. By order of hierarchy, the molten data value column will be of type 'double'. All measure variables not of type 'double' will be coerced too. Check DETAILS in ?melt.data.table for more on coercion.

Below are examples of data tables that do and do not raise the warning you see. In the first case, column B contains double values and column C contains integers. This raises the warning about values of different types. In the second case, columns B and C are both doubles and there is no warning. What types of data do your columns have? Is conversion to double a problem for you?

DT <- data.table(A=c("A","B","C"),B=c(12.2,5.4,23.4),C=c(1L,2L,3L))
melt(DT,id.vars = "A")

DT2 <- data.table(A=c("A","B","C"),B=c(12.2,5.4,23.4),C=c(1.0,2.0,3.0))
melt(DT2,id.vars = "A")

Can you post a bit of data from the data table that you are trying to melt and also the actual melt command you are using? You can use the dput function to make a cut-and-paste friendly output. Please post the out put of something like:

dput(head(dtODU))

the actual melt command I am using:
DTODU <- melt(dtODU[,.SD,.SDcols=is.numeric],id.vars=c(1))

dput(head(dtODU))
structure(list(Smp = 12:17, Time = structure(c(1606221332, 1606221333, 
1606221334, 1606221335, 1606221336, 1606221337), class = c("POSIXct", 
"POSIXt"), tzone = "EST"), OMainMode = c("COOL", "COOL", "COOL", 
"COOL", "COOL", "COOL"), RVState = c("COOL", "COOL", "COOL", 
"COOL", "COOL", "COOL"), ODUFault = c("NO-FAULT", "NO-FAULT", 
"NO-FAULT", "NO-FAULT", "NO-FAULT", "NO-FAULT"), LastFault = c("(31)OPER-CON-EXCEEDED", 
"(31)OPER-CON-EXCEEDED", "(31)OPER-CON-EXCEEDED", "(31)OPER-CON-EXCEEDED", 
"(31)OPER-CON-EXCEEDED", "(31)OPER-CON-EXCEEDED"), TargetFreq = c(75L, 
75L, 75L, 75L, 75L, 75L), ActualFreq = c(75L, 75L, 75L, 75L, 
75L, 75L), OAT = c(46L, 46L, 46L, 47L, 46L, 46L), HST = c(84L, 
84L, 84L, 84L, 84L, 84L), OCT = c(54L, 54L, 54L, 54L, 54L, 54L
), CTT = c(86.2, 86.2, 86.2, 86.2, 86.2, 86.2), TCTT = c(85L, 
85L, 85L, 85L, 85L, 85L), OMT = c(54L, 54L, 54L, 54L, 54L, 54L
), CompACCurr = c(0L, 0L, 0L, 0L, 0L, 0L), CompDCCurr = c(148L, 
148L, 148L, 148L, 148L, 148L), SystemPower = c(0L, 0L, 0L, 0L, 
0L, 0L), OFanSpd1 = c(85L, 86L, 86L, 86L, 85L, 85L), OFanSpd2 = c(86L, 
86L, 86L, 85L, 85L, 85L), ODUMsg. = c(19L, 21L, 21L, 23L, 25L, 
25L), TARG_EEV1 = c(332L, 332L, 332L, 332L, 332L, 332L), ACT_EEV1 = c(360L, 
360L, 360L, 360L, 360L, 360L), RGLT1 = c(6L, 6L, 6L, 6L, 6L, 
6L), TARG_EEV3 = c(396L, 396L, 396L, 396L, 396L, 396L), ACT_EEV3 = c(396L, 
396L, 396L, 396L, 396L, 396L), RGLT3 = c(6L, 6L, 6L, 6L, 6L, 
6L), TARG_EEV4 = c(378L, 378L, 378L, 378L, 378L, 378L), ACT_EEV4 = c(348L, 
348L, 348L, 348L, 348L, 348L), RGLT4 = c(8L, 8L, 8L, 8L, 8L, 
8L)), row.names = c(NA, -6L), class = c("data.table", "data.frame"
), .internal.selfref = <pointer: 0x000002245b4c1ef0>)

as @FJCC asked, is converting to double a problem? This warning will come up because some of your numeric columns are integers and some are double. It's just letting you know that the value column in the resultant melted data.table will be a double. It needs to choose one type since the column will be a vector and double is the most obvious choice in these situations.

You can always suppress warnings if you want. Or you can just convert all your integer columns to doubles or numerics

this code works:

changeCols <-dtODU[,colnames(.SD),.SDcols=is.integer]
dtODU[, (changeCols) := lapply(.SD,na.rm = T, as.numeric),.SDcols =changeCols]
unlist(sapply(dtODU, class))
        Smp       Time1       Time2   OMainMode     RVState    ODUFault   LastFault  TargetFreq 
  "integer"   "POSIXct"    "POSIXt" "character" "character" "character" "character"   "numeric" 
 ActualFreq         OAT         HST         OCT         CTT        TCTT         OMT  CompACCurr 
  "numeric"   "numeric"   "numeric"   "numeric"   "numeric"   "numeric"   "numeric"   "numeric" 
 CompDCCurr SystemPower    OFanSpd1    OFanSpd2     ODUMsg.   TARG_EEV1    ACT_EEV1       RGLT1 
  "numeric"   "numeric"   "numeric"   "numeric"   "numeric"   "numeric"   "numeric"   "numeric" 
  TARG_EEV3    ACT_EEV3       RGLT3   TARG_EEV4    ACT_EEV4       RGLT4 
  "numeric"   "numeric"   "numeric"   "numeric"   "numeric"   "numeric" 
DTODU <- melt(dtODU[,.SD,.SDcols=is.numeric],id.vars=c(1))
> 
> 

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

does not convert the columns to numeric (Float) !!!
What should be corrected?

changeCols <-dtODU[,colnames(.SD),.SDcols=is.integer] 
dtODU[,lapply(.SD, as.numeric), .SDcols = changeCols]

str(dtODU)
Classes ‘data.table’ and 'data.frame':	86387 obs. of  29 variables:
 $ Smp        : int  12 13 14 15 16 17 18 19 20 21 ...
 $ Time       : POSIXct, format: "2020-11-24 07:35:32" "2020-11-24 07:35:33" "2020-11-24 07:35:34" ...
 $ OCT        : int  54 54 54 54 54 54 54 54 53 53 ...
 $ CTT        : num  86.2 86.2 86.2 86.2 86.2 86.2 86.2 86 86.2 86.2 ...
 $ TCTT       : int  85 85 85 85 85 85 85 85 85 85 ...

 - attr(*, ".internal.selfref")=<externalptr> 

It can be seen that there is at least one Float variable.
How to handle this situation and avoid the alert?

str(dtODU)
Classes ‘data.table’ and 'data.frame':	86387 obs. of  29 variables:
 $ Smp        : int  12 13 14 15 16 17 18 19 20 21 ...
 $ Time       : POSIXct, format: "2020-11-24 07:35:32" "2020-11-24 07:35:33" "2020-11-24 07:35:34" ...
 $ OCT        : int  54 54 54 54 54 54 54 54 53 53 ...
 $ CTT        : num  86.2 86.2 86.2 86.2 86.2 86.2 86.2 86 86.2 86.2 ...