Conversion of factors to numerics

Hi all,

We found that in native R the function “as.numeric” (and similarly the function “as integer”) when is used to convert a variable of class factor to a variable of class numeric, it returns the underlying level codes of the factor instead of converting the actual values to numbers. For example it converts the factor vector (0 1 1 2 1 0 1 0 2 2 2 1) with Levels: 0 1 2, to the numeric vector (1 2 2 3 2 1 2 1 3 3 3 2). This behaviour occurs also in DataSHIELD when the ds.asNumeric or the ds.asInteger functions are used to convert a factor variable to a numeric or integer respectively. However, if the converted variable is used in a statistical analysis it can lead to incorrect results. Therefore, we have modified the ds.asNumeric and the ds.asInteger functions, to first convert the input object to a character and then to a numeric or integer. The updated version of both functions will be included in the 5.1 version of DataSHIELD.