在R中设置3D矩阵并访问某些元素 [英] Setting up a 3D matrix in R and accessing certain elements
本文介绍了在R中设置3D矩阵并访问某些元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在R中建立3D矩阵.我想这很简单.但是,到目前为止,我还没有找到解决方案. 假设我们要创建一个365x6x4矩阵. 同样重要的是我如何更改矩阵中的一个条目. 假设我们要为元素[304,5,2]分配值204. 非常感谢您的回答!
I am trying to set up a 3D matrix in R. I guess this is an easy one. However, I didn't find a solution so far. Let's say we want to create a 365x6x4 matrix. Also crucial form me is how I can change one entry in the matrix. Let's say we want to assign the value 204 to the element [304,5,2]. I highly appreciate your answer!
谢谢!最好,F
推荐答案
尝试一下:
ar <- array(someData, c(365, 6, 4));
ar[304,5,2] <- 204;
someData
可能是
someData <- rep(0, 365*6*4);
甚至更好
someData <- rep(NaN, 365*6*4);
这篇关于在R中设置3D矩阵并访问某些元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文