我正在阅读 R 中 Matrix 包的说明。但我无法理解p
函数中的参数:
sparseMatrix(i = ep, j = ep, p, x, dims, dimnames,
symmetric = FALSE, index1 = TRUE,
giveCsparse = TRUE, check = TRUE)
根据http://stat.ethz.ch/R-manual/R-devel/library/Matrix/html/sparseMatrix.html http://stat.ethz.ch/R-manual/R-devel/library/Matrix/html/sparseMatrix.html
p:
指针的数字(整数值)向量,每一列(或行)一个,指向
列(或行)中元素的初始(从零开始)索引。恰好是 i、j 或 p 之一
一定失踪了。
我估计p
用于行或列索引的压缩表示,因为在其中包含多个元素是浪费的i
or j
具有相同的值来表示单个行/列。但是当我尝试提供的示例时,我仍然不明白如何p
正在控制哪个元素x
转到哪一行/哪一列
dn <- list(LETTERS[1:3], letters[1:5])
## pointer vectors can be used, and the (i,x) slots are sorted if necessary:
m <- sparseMatrix(i = c(3,1, 3:2, 2:1), p= c(0:2, 4,4,6), x = 1:6, dimnames = dn)