How to coerce a list object to type 'double'

前端 未结 5 631
执笔经年
执笔经年 2020-12-02 06:13

The code:

a <- structure(list(`X$Days` = c(\"10\", \"38\", \"66\", \"101\", \"129\", \"185\", \"283\", 
                                 \"374\")), .Names         


        
5条回答
  •  没有蜡笔的小新
    2020-12-02 07:16

    If you want to convert all elements of a to a single numeric vector and length(a) is greater than 1 (OK, even if it is of length 1), you could unlist the object first and then convert.

    as.numeric(unlist(a))
    # [1]  10  38  66 101 129 185 283 374
    

    Bear in mind that there aren't any quality controls here. Also, X$Days a mighty odd name.

提交回复
热议问题