我用read.table
读取了一个只包含数值的txt文件,但是当我尝试对数据执行计算时,比如用mean()
求平均值,它就会告诉我参数不是数值。
dat= read.table("oldfaithful.txt", header= FALSE)
dat= as.numeric(c(dat))
avg= mean(dat)
Warning message:
In mean.default(dat) : argument is not numeric or logical: returning NA
Error: (list) object cannot be coerced to type 'double'
下面是txt.file的一个片段
216
108
200
137
272
173
282
216
117
261
110
235
252
105
282
这是打印出来的dat的样子
V1
1 216
2 108
3 200
4 137
5 272
6 173
7 282
8 216
9 117
10 261
11 110
12 235
13 252
14 105
15 282
发布于 2019-05-21 07:08:12
对不起,我可能应该把最后一条评论放到答案里。
您需要仅取数据框中的V1列的平均值,而不是整个数据框。
我认为最后一行代码应该是
avg = mean(dat$V1)
https://stackoverflow.com/questions/56229101
复制相似问题