我想按行添加數據(並按表)。然而,我下面嘗試的方法都沒有工作。我確信有一個非常簡單的答案,但它逃脫了我,我找不到通過搜索互聯網的答案。感謝您的任何建議。按行添加數據到陣列
I <- 4 # rows
J <- 2 # columns
K <- 3 # sheets
my.data <- array(0 , c(I,J,K))
sheet1 <- c(2,5)
sheet2 <- c(7,1)
sheet3 <- c(4,4)
# desired result
#
# , , 1
#
# [,1] [,2]
# [1,] 2 5
# [2,] 2 5
# [3,] 2 5
# [4,] 2 5
#
# , , 2
#
# [,1] [,2]
# [1,] 7 1
# [2,] 7 1
# [3,] 7 1
# [4,] 7 1
#
# , , 3
#
# [,1] [,2]
# [1,] 4 4
# [2,] 4 4
# [3,] 4 4
# [4,] 4 4
這些都不工作:
my.data <- array(0 , c(I,J,K)) ; my.data[1:I, , 1] <- sheet1 ; my.data
my.data <- array(0 , c(I,J,K)) ; my.data[, 1:J, 1] <- sheet1 ; my.data
my.data <- array(0 , c(I,J,K)) ; aperm(my.data[1:I,,1], perm=sheet1) ; my.data