Warning message:In mean.default(df) : argument is not numeric or logical: returning NA
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Warning message:In mean.default(df) : argument is not numeric or logical: returning NA相关的知识,希望对你有一定的参考价值。
Warning message:
In mean.default(df) : argument is not numeric or logical: returning NA
目录
Warning message:In mean.default(df) : argument is not numeric or logical: returning NA
问题:
字符串是没有办法计算均值的,只有数字才会有这些统计量;
#create data frame
df <- data.frame(team=c('A', 'B', 'C', 'D', 'E'),
points=c(99, 90, 86, 88, 95),
assists=c(33, 28, 31, 39, 34),
rebounds=c(30, 28, 24, 24, 28))
#view data frame
df
#attempt to calculate mean of entire data frame
mean(df)
解决:
#只对单个数值列计算均值
#calculate mean of points column
mean(df$points)
[1] 91.6
#使用sapply方法(只有非数值列会返回NA,其他列正常)
#calculate mean of every column in data frame
sapply(df, mean, 2)
team points assists rebounds
NA 90 33 28
Warning message:
In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
#使用sapply方法(只有对数值列进行计算均值)
#calculate mean of each numeric column
sapply(df[c('points', 'assists', 'rebounds')], mean, 2)
points assists rebounds
90 33 28
完整错误:
#attempt to calculate mean of character column
mean(df$team)
Warning message:
In mean.default(df$team) : argument is not numeric or logical: returning NA
#attempt to calculate mean of entire data frame
mean(df)
Warning message:
In mean.default(df) : argument is not numeric or logical: returning NA
以上是关于Warning message:In mean.default(df) : argument is not numeric or logical: returning NA的主要内容,如果未能解决你的问题,请参考以下文章
Warning message:In Ops.factor(x, 2) : ‘^’ not meaningful for factors
Warning message:In mean.default(df) : argument is not numeric or logical: returning NA
Referenced file contains errors For more information, right click on the message in the Problems V
Dlib - 如何使用 loss_mean_squared_multioutput 训练标签类型?
有关JSF-JPA集成报 Could not find a setter for property message in class ..问题