Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.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_Loops_Missing Data - Fatal编程技术网

R 每行偏度

R 每行偏度,r,loops,missing-data,R,Loops,Missing Data,我有以下资料: d1 <- c(-10,2,3,4,5,6, NA, NA, NA); d2 <- c(1,2,3,4,5,6,7, NA, NA); d3 <- c(1,2,3,4,5,6,700, 800, 900); d <- rbind(d1, d2, d3); d <- data.matrix(d) d1使用apply: apply(d, 1, skewness, na.rm =TRUE) 您的for循环的固定版本: ske

我有以下资料:

d1    <- c(-10,2,3,4,5,6, NA, NA, NA);
d2    <- c(1,2,3,4,5,6,7, NA, NA); 
d3    <- c(1,2,3,4,5,6,700, 800, 900);
d     <- rbind(d1, d2, d3); d <- data.matrix(d)

d1使用
apply

apply(d, 1, skewness, na.rm =TRUE)
您的
for
循环的固定版本:

skew <- vector("numeric", nrow(d))  # first pre allocate to hold the result
for (i in 1:nrow(d)){
  skew[i] <- skewness(d[i, ], na.rm=TRUE) # your matrix indexing was wrong
}
setNames(skew, rownames(d))  # just for names
skew您还可以使用:

colSkewness(d)
colSkewness(d)