[R] What exactly is an dgCMatrix-class. There are so many attributes.
William Dunlap
wdunlap at tibco.com
Fri Oct 20 20:42:36 CEST 2017
You should not really have worry about the internal structure of such a
thing - just treat it like a matrix. E.g.,
> train$data[1:3,1:3] # dots mean 0's
3 x 3 sparse Matrix of class "dgCMatrix"
cap-shape=bell cap-shape=conical cap-shape=convex
[1,] . . 1
[2,] . . 1
[3,] 1 . .
> dim(train$data)
[1] 6513 126
> p <- train$data %*% matrix(1:126, ncol=1)
> dim(p)
[1] 6513 1
If that doesn't work in some situation, convert it to a matrix with
as.matrix.
To see the details, in R, type
class?dgCMatrix
or
help("dgCMatrix-class")
In a browser seach window type
R dgCmatrix
You should not have to make use of those details in your code.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Fri, Oct 20, 2017 at 11:11 AM, C W <tmrsg11 at gmail.com> wrote:
> Dear R list,
>
> I came across dgCMatrix. I believe this class is associated with sparse
> matrix.
>
> I see there are 8 attributes to train$data, I am confused why are there so
> many, some are vectors, what do they do?
>
> Here's the R code:
>
> library(xgboost)
> data(agaricus.train, package='xgboost')
> data(agaricus.test, package='xgboost')
> train <- agaricus.train
> test <- agaricus.test
> attributes(train$data)
>
> Where is the data, is it in $p, $i, or $x?
>
> Thank you very much!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list