0
点赞
收藏
分享

微信扫一扫

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'

举报

相关推荐

0 条评论