Skip to content

Commit

Permalink
Fix matrix attributes not sliced (#4311)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Francois Zinque authored and hetong007 committed Apr 10, 2019
1 parent 5c25755 commit 956e73f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions R-package/R/xgb.DMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,17 @@ slice.xgb.DMatrix <- function(object, idxset, ...) {

attr_list <- attributes(object)
nr <- nrow(object)
len <- sapply(attr_list, length)
len <- sapply(attr_list, NROW)
ind <- which(len == nr)
if (length(ind) > 0) {
nms <- names(attr_list)[ind]
for (i in seq_along(ind)) {
attr(ret, nms[i]) <- attr(object, nms[i])[idxset]
obj_attr <- attr(object, nms[i])
if (NCOL(obj_attr) > 1) {
attr(ret, nms[i]) <- obj_attr[idxset,]
} else {
attr(ret, nms[i]) <- obj_attr[idxset]
}
}
}
return(structure(ret, class = "xgb.DMatrix"))
Expand Down

0 comments on commit 956e73f

Please sign in to comment.