Skip to content

Instantly share code, notes, and snippets.

@MyKo101
Created November 21, 2020 15:16
Show Gist options
  • Save MyKo101/89ba807395a3d907b56f51cd56ee4811 to your computer and use it in GitHub Desktop.
Save MyKo101/89ba807395a3d907b56f51cd56ee4811 to your computer and use it in GitHub Desktop.
`[[.data.frame` <- function(x,...,exact=TRUE) {
na <- nargs() - !missing(exact)
if (!all(names(sys.call()) %in% c("", "exact")))
warning("named arguments other than 'exact' are discouraged")
if (na < 3L)
{
(function(x, i, exact)
{
if (is.matrix(i))
{
as.matrix(x)[[i]]
} else {
.subset2(x, i, exact = exact)
})(x, ..., exact = exact)
} else if(missing(..2)){
as.matrix(x)[..1,]
} else{
col <- .subset2(x, ..2, exact = exact)
i <- if (is.character(..1))
{
pmatch(..1, row.names(x), duplicates.ok = TRUE)
} else {
..1
}
col[[i, exact = exact]]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment