Skip to content
Prev 374723 / 398506 Next

remove rows of a matrix by part of its row name

I think it is simpler to use !grepl() instead of -grep() here, since
subscripting with logicals works properly when there are no matches.
Also, since mat is a matrix, add the argument drop=FALSE so the
result is a matrix when all but one rows are omitted.  E.g.,
dimnames=list(c("One","Two","Three"),c("A","B")))
row wanted
 Named int [1:2] 1 4
 - attr(*, "names")= chr [1:2] "A" "B"
unwanted rows
 int[0 , 1:2]
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:2] "A" "B"
matrix if only one row wanted
 int [1, 1:2] 1 4
 - attr(*, "dimnames")=List of 2
  ..$ : chr "One"
  ..$ : chr [1:2] "A" "B"
is no unwanted rows
 int [1:3, 1:2] 1 2 3 4 5 6
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:3] "One" "Two" "Three"
  ..$ : chr [1:2] "A" "B"



Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Tue, May 22, 2018 at 4:34 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote: