Skip to content
Prev 55310 / 63424 Next

Subsetting the "ROW"s of an object

El vie., 8 jun. 2018 a las 17:46, Hadley Wickham
(<h.wickham at gmail.com>) escribi?:
The following code seems to work. The only minor drawback is that, for
the last case, the output is not a data frame.

subset_ROW <- function(x, i) {
  nd <- length(dim(x))
  if (nd <= 1L)
    return(x[i])
  xx <- apply(x, 2:nd, `[`, i, drop=FALSE)
  dim(xx) <- c(length(i), dim(x)[-1])
  xx
}

I?aki