library(dgcmatrix) # 创建一个5行3列的稀疏矩阵 mat <- dgCMatrix(nr = 5, nc = 3) # 填充矩阵数据 mat[1, 1] <- 1 mat[2, 2] <- 2 mat[3, 3] <- 3 mat[4, 2] <- 4 mat[5, 1] <- 5 # 打印矩阵 print(mat) ``` 输出结果如下: ``` 5 x 3 sparse Matrix of class "dgC...
dgCMatrix 即Compressed, sparse, column-oriented numeric matrices,类比于 Python 中的csc_matrix,是一种按列压缩的稀疏矩阵格式,由三个一维数组indptr, indices, data组成。dgCMatrxi是R 包 Matrix 中标准的格式,也是最常见的格式,单细胞多组学稀疏数据存储一般采用该格式。 dgRMatrix 即Sparse Compressed, Row-orie...
coef(cvfit, s = "lambda.1se") # 这个是默认值 ## 31 x 1 sparse Matrix of class "dgCMatrix" ## s1 ## (Intercept) 0.542143513 ## V1 . ## V2 0.043727971 ## V3 -0.022970497 ## V4 -0.130364268 ## V5 -0.019367732 ## V6 -0.073722441 ## V7 . ## V8 -0.041158945 ## V9 0.03633454...
先用as.matrix()转换成matrix再write.csv
coef(fit,s=0.1)##21x1sparse Matrixofclass"dgCMatrix"##1##(Intercept)0.150928##V11.320597##V2.##V30.675110##V4.##V5-0.817412##V60.521437##V70.004829##V80.319416##V9.##V10.##V110.142499##V12.##V13.##V14-1.059979##V15.##V16.##V17.##V18.##V19.##V20-1.021874 ...
CSC(dgCMatrix)是CSR相对应的一种方式,即按列压缩稀疏矩阵 一、 原理 1. 10X Genomics单细胞测序原理 上图最左边为带有标记的凝胶微珠,凝胶微珠逐渐向右流去,在第一个十字路口,放进去细胞悬液和酶,然后凝胶微珠和细胞悬液和酶一起向右流动,到第二个十字路口遇到油,变为油包水结构,正常情况下为一个油包水...
##21x1sparse Matrixofclass"dgCMatrix"##1##(Intercept)0.149041059##V11.302684272##V20.035835380##V30.719936146##V40.036473087##V5-0.863490158##V60.605750873##V70.123446432##V80.376890626##V9-0.040012847##V100.105999328##V110.240967604##V12-0.066363634##V13-0.042048935##V14-1.092107794##V15-0.119566353##...
## 21 x 1 sparse Matrix of class "dgCMatrix" ## 1 ## (Intercept) 0.150928 ## V1 1.320597 ## V2 . ## V3 0.675110 ## V4 . ## V5 -0.817412 ## V6 0.521437 ## V7 0.004829 ## V8 0.319416 ## V9 . ## V10 . ## V11 0.142499 ...
sparse.gbm.C <-as(counts,"dgCMatrix") ### convert to csc_matrix sparse.gbm.R <-as(counts,"dgRMatrix") ### convert to csr_matrix 创建列压缩的稀疏矩阵(csc_matrix)还可以用方法sparse.gbm <- Matrix::Matrix(counts, sparse = T),但是该方法在大型矩阵中较为低效。
## 21 x 1 sparse Matrix of class "dgCMatrix" ## 1 ## (Intercept) 0.149041059 ## V1 1.302684272 ## V2 0.035835380 ## V3 0.719936146 ## V4 0.036473087 ## V5 -0.863490158 ## V6 0.605750873 ## V7 0.123446432 ## V8 0.376890626 ## V9 -0.040012847 ...