Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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中的平均绝对偏差(MAD)_R_Robustness - Fatal编程技术网

如何求r中的平均绝对偏差(MAD)

如何求r中的平均绝对偏差(MAD),r,robustness,R,Robustness,我发现r的平均绝对偏差。当我运行它时,r给我一个错误,你应该有数字数据。此外,当我将数据转换为数字时,它会给我一个错误,即x必须是原子的 md <- mad(x, center = median(x), constant = 1.4826, na.rm = FALSE, low = FALSE, high = FALSE) Error in median.default(x) : need numeric data md如果你能在这里提供你的x向量,这会很有帮助。它在以下原子

我发现r的平均绝对偏差。当我运行它时,r给我一个错误,你应该有数字数据。此外,当我将数据转换为数字时,它会给我一个错误,即x必须是原子的

md <- mad(x, center = median(x), constant = 1.4826, na.rm = FALSE,
      low = FALSE, high = FALSE)
Error in median.default(x) : need numeric data

md如果你能在这里提供你的x向量,这会很有帮助。它在以下原子向量和非数值向量中工作良好

# numeric vector
> x <- 1:10
> mad(x, center = median(x), constant = 1.4826, na.rm = FALSE, low = FALSE, high = FALSE)
> 3.7065

# non-numeric vector
> x <- c(TRUE, FALSE, T, F)
> mad(x)
> 0.7413

# atomic vector
> x <- c(1L, 6L, 10L)
> mad(x)
> 10

# works even with NA's in the vector
> x <- c(1L, 6L, 10L, NA)
> mad(x, na.rm = TRUE)
> 5.9304
#数字向量
>x mad(x,中心=中值(x),常数=1.4826,na.rm=假,低=假,高=假)
> 3.7065
#非数值向量
>x疯狂(x)
> 0.7413
#原子矢量
>x疯狂(x)
> 10
#即使矢量中的NA也有效
>x mad(x,na.rm=TRUE)
> 5.9304

如果这是一个关于数据类型的问题,我们需要在您处理数据时提供一个数据样本,这样做的不仅仅是猜测。关于制作一个可复制的例子
# numeric vector
> x <- 1:10
> mad(x, center = median(x), constant = 1.4826, na.rm = FALSE, low = FALSE, high = FALSE)
> 3.7065

# non-numeric vector
> x <- c(TRUE, FALSE, T, F)
> mad(x)
> 0.7413

# atomic vector
> x <- c(1L, 6L, 10L)
> mad(x)
> 10

# works even with NA's in the vector
> x <- c(1L, 6L, 10L, NA)
> mad(x, na.rm = TRUE)
> 5.9304