Error: ‘list‘ object cannot be coerced to type ‘double‘
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Error: ‘list‘ object cannot be coerced to type ‘double‘相关的知识,希望对你有一定的参考价值。
Error: 'list' object cannot be coerced to type 'double'
目录
Error: 'list' object cannot be coerced to type 'double'
问题:
试图将list对象转化为double类型,肯定是会出问题的;
#create list
x <- list(1:5, 6:9, 7)
#display list
x
#attempt to convert list to numeric
x_num <- as.numeric(x)
解决:
#正确的做法是,先使用unlist进行处理
#create list
x <- list(1:5, 6:9, 7)
#convert list to numeric
x_num <- as.numeric(unlist(x))
#display numeric values
x_num
[1] 1 2 3 4 5 6 7 8 9 7
#class函数查看数据类型
> class(x)
[1] "list"
> class(unlist(x))
[1] "numeric"
>
完整错误:
> #attempt to convert list to numeric
> x_num <- as.numeric(x)
Error: 'list' object cannot be coerced to type 'double'
以上是关于Error: ‘list‘ object cannot be coerced to type ‘double‘的主要内容,如果未能解决你的问题,请参考以下文章
malloc: *** error for object 0x6080000bd200: Invalid pointer dequeued from free list *** set a break
JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception i
ffprobe: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No
uni-app的报错提示:Error in nextTick: “TypeError: Right-hand side of ‘instanceof‘ is not an object“