image(1:9) Error in image.default(1:9) : argument -6ren">
gpt4 book ai didi

r - "matrix-like?"的(精确)含义是什么

转载 作者:行者123 更新时间:2023-12-04 13:16:20 27 4
gpt4 key购买 nike

我想创建不一定是“正确”矩阵的“类矩阵”对象。但是,确切地说,“类矩阵”是什么意思?

示例 1

> image(1:9)
Error in image.default(1:9) : argument must be matrix-like

示例 2

在 R 语言定义(在 v3.3.1 中,第 3.4.3 节)中,它是 hapax legomenon (强调):

[An] example of a class method for [ is… if two indices are supplied (even if one is empty) it creates matrix-like indexing…



示例 3
help(scale)的标题阅读,“矩阵式对象的缩放和居中”(强调)。那里似乎有一个线索:

numeric-alike means that as.numeric(.) will be applied successfully if is.numeric(.) is not true.

最佳答案

类矩阵数据是表格形式的数据,带有dim属性集。但是length(dim(obj))必须等于 2,矩阵是二维对象。

引自 Advanced R by Hadley Wickham :

Matrices and arrays

Adding a dim attribute to an atomic vector allows it to behave like a multi-dimensional array. A special case of the array is the matrix, which has two dimensions. Matrices are used commonly as part of the mathematical machinery of statistics. Arrays are much rarer, but worth being aware of.

Matrices and arrays are created with matrix() and array(), or by using the assignment form of dim()



另见 help("dim") page .

例子:
x <- 1:9
image(x) # error

y <- 1:9
dim(y) <- c(3, 3)
image(y)

enter image description here

关于r - "matrix-like?"的(精确)含义是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60062805/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com