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
R 如何使这个表达式更小、更漂亮?_R - Fatal编程技术网

R 如何使这个表达式更小、更漂亮?

R 如何使这个表达式更小、更漂亮?,r,R,可以在R中压缩此表达式: for(j in 1:dim(data)[3]) data[,,j] <- f(data[,,j]) 对于(j in 1:dim(data)[3])数据[,j]尝试以下操作: a[] <- apply(a, 3, f) 比如说, f <- function(x) mean(x) * x^0 a <- array(1:24, 2:4) aa <- replace(a, TRUE, apply(a, 3, f)) for(i in 1:

可以在R中压缩此表达式:

for(j in 1:dim(data)[3]) data[,,j] <- f(data[,,j])
对于(j in 1:dim(data)[3])数据[,j]尝试以下操作:

a[] <- apply(a, 3, f)
比如说,

f <- function(x) mean(x) * x^0
a <- array(1:24, 2:4)

aa <- replace(a, TRUE, apply(a, 3, f))

for(i in 1:4) a[,,i] <- f(a[,,i])

identical(a, aa)
# [1] TRUE
f试试这个:

a[] <- apply(a, 3, f)
比如说,

f <- function(x) mean(x) * x^0
a <- array(1:24, 2:4)

aa <- replace(a, TRUE, apply(a, 3, f))

for(i in 1:4) a[,,i] <- f(a[,,i])

identical(a, aa)
# [1] TRUE
f