I have a custom function that includes the function IF. When I use that function in a data.table, I get a warning that says "the condition has length > 1 and only the first element will be used".
I think the function may be applied to all rows in the column rather than one row at a time as needed, but I am not certain.
Is anyone aware of why this warning appears?
My function is:
HeatIndex<-function(TempC,RH)
{
TFarheit= TempC * 1.8 + 32
if( TFarheit <80 ) {
Te=TempC /15
HI = Te/15
} else {
TA=TempC /11
HI = TA/125
}
HI= (HI - 32) / 1.8
return(HI )
}
A sample of the data:
HeatINDEX=data.table(Ave_MeanRH=c(0,100), Ave_MeanT=c(10,20)) #create data.table
And applying the function to the data
HeatINDEX[,HI:=HeatIndex(HeatINDEX$Ave_MeanT, HeatINDEX$Ave_MeanRH)]