Skip to content

Instantly share code, notes, and snippets.

@bachmeil
Last active February 19, 2020 20:12
Show Gist options
  • Save bachmeil/289c95b1502e9de01e9d70b90d9f3e64 to your computer and use it in GitHub Desktop.
Save bachmeil/289c95b1502e9de01e9d70b90d9f3e64 to your computer and use it in GitHub Desktop.
In case you want dim to work for vectors
dim <- function(x) {
if (is.vector(x)) {
return(length(x))
} else {
return(.Primitive("dim")(x))
}
}
# Test code
# v <- rnorm(100)
# dim(v) # returns 100, not NULL
# m <- matrix(1:25, ncol=5)
# dim(m) # returns the dimensions as usual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment