R Subset by row numbers -
i have large matrix “a” (14 columns 250 000 rows). has no id column.
i have matrix “b” (14x1) 14 numbers.
1 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191
i subset “a” taking rows have number in b. eg. row 1, 3, 7, 15, 31, etc.
i have tried following:
newa <- a[nrow(a) %in% c(b),]
i didn’t work. have tried add id column large matrix (e.g. a$id <- 1:nrow(a)
didn’t work either.
try converting b numeric vector , use index - works matrices regardless of how many rows , columns have.
b<-as.numeric(as.character(b)) newa<-a[b,]
edit - refined clarity , information on applicability matrices of dimensions.
Comments
Post a Comment