【R】 Error in is.data.frame(x) : (list) object cannot be coerced to type 'double'

对于不经常使用R语言进行编程的人来说,一接触R语言可能会遇到各种各样的问题。今天在使用R语言读取数据的时候遇到了如下的错误:

Error in is.data.frame(x) : 
  (list) object cannot be coerced to type 'double'

读取数据的代码如下:(其中interval_estimated()是自己定义的一个方法)

df <- read.csv("C://Users//Machenike//Desktop//zzz//data.csv", header = FALSE, sep = "\t")
interval_estimated(df[3])
Error in is.data.frame(x) : 
  (list) object cannot be coerced to type 'double'
In addition: Warning message:
In mean.default(x) :
 Show Traceback
 
 Rerun with Debug
 Error in is.data.frame(x) : 
  (list) object cannot be coerced to type 'double'

数据内容如下:

head(df)
           V1 V2         V3
1 1.01121e+19  1 0.03000000
2 1.01121e+19  1 0.03000000
3 1.01121e+19  1 0.03000002
4 1.01121e+19  1 0.00000000
5 1.01121e+19  1 0.03000000
6 1.01121e+19  1 0.00000000

解决办法:

是因为读入的是数据框形式的,此处调用不应该使用df[3],应使用df[,3],如下:

interval_estimated(df[,3])
       mean     df          a          b
1 0.0314915 404901 0.02930638 0.03367661

猜你喜欢

转载自blog.csdn.net/gdkyxy2013/article/details/80976696
今日推荐