For some reason, this gsub line in my for loop isn't executing. Basically, what I hope to do is for a specific character at the beginning and end of an element, I would like to take it out. So in my example code, I only keep values that start with 0 or get rid it it otherwise (in the code I'm working with everything stored in the matrix is a character vector, and what I want to do is remove a repeating specific character at the beginning and end of each vector). However, nothing is changed about m2 once my script finishes running
m2 <- matrix( c(2, 0, 0, 0, 2, 0, 0, 0, 2), nrow=3, ncol=3)
rownames(m2) <- c("a", "d", "e")
colnames(m2) <- c("x", "w", "z")
for (i in 1:length(rownames(m2))){
for (j in 1:length(colnames(m2))){
if (substr(m2[i,j], 1, 1) == "0") {
m2 <- m2
} else (m2 <- gsub("^.", "", m2))
}
}