Re: [R] Extract row as NA with no matching name

2019-08-08 Thread PIKAL Petr
some",] C.1 C.2 C.3 NA NA NA NA Cheers Petr > -Original Message- > From: R-help On Behalf Of Christofer Bogaso > Sent: Thursday, August 8, 2019 5:44 PM > To: r-help > Subject: [R] Extract row as NA with no matching name > > Hi, > > Let say I have b

Re: [R] Extract row as NA with no matching name

2019-08-08 Thread David Winsemius
I don't know a clean way of delivering that result but if you use logical indexing you can get an empty matrix with three columns: str( mdat["nope" %in% rownames(mdat), ] )  num[0 , 1:3]  - attr(*, "dimnames")=List of 2   ..$ : NULL   ..$ : chr [1:3] "C.1" "C.2" "C.3" # it prints thus to the c

[R] Extract row as NA with no matching name

2019-08-08 Thread Christofer Bogaso
Hi, Let say I have below matrix mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol = 3, byrow = TRUE, dimnames = list(c("row1", "row2"), c("C.1", "C.2", "C.3"))) Now I can extract a raw by rowname as > mdat['row1', ] C.1 C.2 C.3 1 2 3 Howe