R初学者:参数不是数字或逻辑:返回NA [英] R Beginner: argument is not numeric or logical: returning NA

查看:3320
本文介绍了R初学者:参数不是数字或逻辑:返回NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个R初学者,很难做任何事情。我有一个来自excel文件的数据集,但现在是一个 .csv 文件,有两列,一个是不完整的。由于某些原因,每当我尝试对数据执行基本的统计操作时,我会收到以下消息:



在mean.default(results)中:参数不是数字或逻辑:返回NA



结果是我的集合。关于解决这个问题的任何建议?

解决方案

从R 3.0.0起意思是(< data 。)                 


数据框是具有唯一行名称的相同行数的变量列表,给定类data.frame。


在你的情况下,结果有两个变量(如果你的描述是正确的)。您可以使用以下任何一种方式获得列的方法:

  lapply(results,mean,na.rm = TRUE)
sapply(results,mean,na.rm = TRUE)
colMeans(results,na.rm = TRUE)


I am an R beginner and having a hard time doing anything in it. I have a data set that originated from an excel file but is now a .csv file with two columns, one being incomplete. For some reason, whenever I try to run basic stat operation on the data, I get this message:

In mean.default(results) : argument is not numeric or logical: returning NA

Results being my set. Any advice on getting around this problem?

解决方案

From R 3.0.0 onwards mean(<data.frame>) is defunct (and passing a data.frame to mean will give the error you state)

A data frame is a list of variables of the same number of rows with unique row names, given class "data.frame".

In your case, result has two variables (if your description is correct) . You could obtain the column means by using any of the following

lapply(results, mean, na.rm = TRUE)
sapply(results, mean, na.rm = TRUE)
colMeans(results, na.rm = TRUE)

这篇关于R初学者:参数不是数字或逻辑:返回NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆