Last active
February 19, 2020 20:12
-
-
Save bachmeil/289c95b1502e9de01e9d70b90d9f3e64 to your computer and use it in GitHub Desktop.
In case you want dim to work for vectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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