as(x, 'double') and as.double(x) are inconsistent

前端 未结 2 540
甜味超标
甜味超标 2020-12-10 01:17
x <- 1:10
str(x)
# int [1:10] 1 2 3 4 5 6 7 8 9 10
str(as.double(x))
# num [1:10] 1 2 3 4 5 6 7 8 9 10 
str(as(x, \'double\'))
# int [1:10] 1 2 3 4 5 6 7 8 9 10
<         


        
2条回答
  •  暖寄归人
    2020-12-10 01:55

    as(x,"double"): Methods are pre-defined for coercing any object to one of the basic datatypes. For example, as(x, "numeric") uses the existing as.numeric function. These built-in methods can be listed by showMethods("coerce"). These functions manage the relations that allow coercing an object to a given class.

    as.double(x): as.double is a generic function. It is identical to as.numeric. Methods should return an object of base type "double". as.double creates, coerces to or test for a double-precision vector.

提交回复
热议问题