[英]Why does my ID numbers change when I make a conversion to a sparse matrix?
head(a)
Output 是
1235 3216 3459 3669 7759 5438
TRUE FALSE TRUE TRUE FALSE FALSE
但是當我跑
Matrix(head(a), sparse = TRUE)
我得到...
[1,] |
[2,] .
[3,] |
[4,] |
[5,] .
[6,] .
為什么數字變了???? 為什么我的output不是這樣的?
1235 |
3216 .
3459 |
3669 |
7759 .
5438 .
我認為您需要手動指定 dimnames:
x <- c('1235'=TRUE,'3216'=FALSE,'3459'=TRUE,'3669'=TRUE,'7759'=FALSE,'5438'=FALSE)
Matrix(x, sparse=TRUE, dimnames=list(names(x)))
#6 x 1 sparse Matrix of class "lgCMatrix"
#
#1235 |
#3216 .
#3459 |
#3669 |
#7759 .
#5438 .
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.