Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 缺少的值不计入系数_R - Fatal编程技术网

R 缺少的值不计入系数

R 缺少的值不计入系数,r,R,在我的数据集中,我有一个字段,类型为因子 在str(年龄) $ age: Factor w/ 75 levels " NA","17","18",..: 25 36 24 39 13 23 35 38 16 28 此字段包含一些NA,我尝试用以下公式计算它们: sum(is.na(as.numeric(unlist(adult[1])))))) 但是它总是给我0,但是我知道有一些遗漏的值 与 使用as.numeric(unlist())我试图将factor转换为num,但也没有成功。看起

在我的数据集中,我有一个字段,类型为因子

str(年龄)

$ age: Factor w/ 75 levels " NA","17","18",..: 25 36 24 39 13 23 35 38 16 28 
此字段包含一些
NA
,我尝试用以下公式计算它们:

 sum(is.na(as.numeric(unlist(adult[1]))))))
但是它总是给我0,但是我知道有一些遗漏的值


使用
as.numeric(unlist())
我试图将factor转换为num,但也没有成功。

看起来它们可能是字符串
“NA”
,而不是缺少NA。例如,
x=系数(c(1:5,“NA”)
。所以你可以用实际缺失的
x[x==“NA”]或者更有害的
“NA”
来替换它,因为它是数据集中第一个
,我使用openrefine用
值替换
。替换(“?”,“NA”)
,根据Matt的建议,可能值得扔掉一个
trimws
there@KamyarParastesh ; 很抱歉,我没听说过openrefine。但是当在中读取数据时,例如使用
read.table
,可以将
na.strings
参数设置为将
设置为missing。