Coerce List Object to Type Double in R (2 Examples)

Coerce List Object to Type Double in R (2 Examples)

目录

Coerce List Object to Type Double in R (2 Examples)

#仿真数据

问题

解决


#仿真数据

my_list <- list(1:3,               
# Example list
                5,
                10:15)
my_list                            
# Print list

#问题

#把列表中的内容转化为数值格式

as.numeric(my_list) # Wrong R code

> as.numeric(my_list) # Wrong R code
Error: 'list' object cannot be coerced to type 'double'

#解决

as.numeric(unlist(my_list)) 

> as.numeric(unlist(my_list)) 
 [1]  1  2  3  5 10 11 12 13 14 15

参考:R

参考:Error: Coerce List Object to Type Double in R (2 Examples)

猜你喜欢

转载自blog.csdn.net/zhongkeyuanchongqing/article/details/121395391
今日推荐