Created
July 6, 2023 17:14
-
-
Save BroVic/8d5cadd673e4b71c376473ef05ac35ff to your computer and use it in GitHub Desktop.
Playing around with R matrices
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
(m = matrix(1:10, nrow = 5, byrow = TRUE)) | |
m[[2]] | |
m[[7]] | |
m[[10]] <- 11L | |
rbind(m, c(11,12)) | |
# Add names | |
i <- 0L | |
dimnames(m) <- lapply(c("x", "y"), function(d) { | |
i <<- i + 1 | |
paste0(d, seq(dim(m)[i])) | |
}) | |
m | |
m["y1"] | |
(my1 <- m[, "y1"]) | |
class(my1) | |
m[["y1"]] # ERROR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment