Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 產生一百萬個常態變數值
- num <- rnorm(1e6)
- # 建一個要輸出的matrix dimention的list
- struct <- list(c(500, 900), c(500, 100), c(250, 350), c(550, 750))
- st <- proc.time()
- # 先把數字切成你要的length (#rows * #columns)
- out <- split(num, rep(seq_along(struct), sapply(struct, Reduce, f = `*`)))
- # 把每個list改成你要的dimension
- for (i in seq_along(struct))
- dim(out[[i]]) <- struct[[i]]
- proc.time() - st
- # user system elapsed
- # 0.17 0.01 0.18
- # 確認結果跟原PO想要的一樣
- all(unlist(out) == num) # TRUE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement