R查找多维数组维尺寸

编程入门 行业动态 更新时间:2024-10-28 15:32:36
本文介绍了R查找多维数组维尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一般相关问题

有人可以指出我要获取R中多维列表或数据结构的维大小的函数/方法吗?

Could someone please point me to functions / methods to get the dimension sizes of a multidimension list or datastructure in R?

了解在更大的数据结构中访问各个元素的方法也将很有用?

It would also be useful to know ways to access individual elements within this bigger datastructure?

下面有关示例输入和输出数据的问题

使用以下命令将输入​​数据转换为输出数据:(以下相关问题):

The Input data is converted to output data using this command:(related question below):

lst <- lapply(split(df2[-1], df2$Column_Zero), function(x) acast(x, Column_Two~Column_One,value.var="Column_Three"))

  • 创建了多少个矩阵?
  • 如何访问创建的每个子矩阵的名称?
  • 每个子矩阵有几列?
  • 每个子矩阵有几行?
  • 哪个子矩阵具有最大/最小的列数/行数?
  • 输入数据:

    Column_Zero, Column_One, Column_Two, Column_Three XX,A, 1, 4 XX,A, 2, 3 XX,A, 3, 77 XX,B, 1, 44 XX,B, 2, 32 XX,B, 3, 770 XX,C, 1, 43 XX,C, 2, 310 XX,C, 3, 68 YY,A1, 1, 4 YY,A1, 2, 3 YY,A1, 3, 77 YY,B1, 1, 44 YY,B1, 2, 32 YY,B1, 3, 770 YY,C1, 1, 43 YY,C1, 2, 310 YY,C1, 3, 68 YY,D2, 1, 4 YY,D2, 2, 5 YY,D2, 3, 6

    ---------等等-----

    --------- And so on -----

    输出数据:

    ------数据表一------

    ------ Data Table one ------

    A, B, C 4, 44, 43 3, 32, 310 77, 770, 68

    ------数据表二------

    ------ Data Table Two ------

    A1, B1, C1, D2 4, 44, 43,4 3, 32, 310,5 77, 770, 68,6

    --------等等-----

    ------ and so on -----

    相关问题: 这是在相关的问题中提出的,我们将在其中拆分数据表并对其进行重塑.因此,了解较小的数据结构/矩阵或数据表的大小变得很重要.

    Related Question: This comes up in the related question, where we are splitting a data table and reshaping it. So it becomes important to know how big the smaller data structures / matrices or data tables are.

    R转换数据表将不同的列值与列名和不同的列值作为另一列的值

    如果有任何不清楚的地方或需要进一步的信息,请告诉我.

    Please let me know if anything is not clear or if you need any further information.

    推荐答案

    问题的答案是

  • 创建了多少个矩阵?
  • 由于每个list元素都是matrix,因此我们可以使用length来查找matrices

    As each of the list element is a matrix, we can use length to find the number of matrices

    length(lst) #[1] 2

    (在一般情况下)如果还有其他对象

    In case if there are other objects (in a general scenario)

    sum(sapply(lst, is.matrix)) #[1] 2

  • 如何访问创建的每个子矩阵的名称?
  • 我们可以使用names

    names(lst)

  • 每个子矩阵有几列?
  • 我们可以通过遍历lst

    sapply(lst, ncol) # XX YY # 3 4

  • 每个子矩阵有几行?
  • 与上述相同,将ncol替换为nrow.我们可以同时使用dim

    It is the same as above by replacing ncol with nrow. We can get both by using dim

    lapply(lst, dim)

  • 哪个子矩阵具有最大/最小的列数/行数?
  • 我们可以在遍历"lst"之后使用which.min或which.max查找索引.

    We can use which.min or which.max to find the index after looping through the 'lst'.

    lst[which.min(sapply(lst, ncol) )] lst[which.max(sapply(lst, ncol))]

    和nrow

    更多推荐

    R查找多维数组维尺寸

    本文发布于:2023-06-08 03:48:47,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/576109.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:多维   数组   尺寸

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!