Skip to content

Instantly share code, notes, and snippets.

@BroVic
Created July 6, 2023 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BroVic/8d5cadd673e4b71c376473ef05ac35ff to your computer and use it in GitHub Desktop.
Save BroVic/8d5cadd673e4b71c376473ef05ac35ff to your computer and use it in GitHub Desktop.
Playing around with R matrices
(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