ryugun
January 8, 2023, 10:29am
1
Hi, I'm new to R so sorry if this is a stupid question. Can anyone explain to me how come my columns and rows for matrix 'test1' isn't renamed after i execute my function? Is my understanding of functions wrong and it's just designed badly?
test1 <- cbind(1:6)
rename <- function(a){
rownames(a) <- c(1:6)
colnames(a) <- "a"
}
rename(test1)
test1
Thanks for your help in advance
I am not totally sure bet what you have is a matrix and I do not think a matrix has as names or colnames.
test1 <- cbind(1:6)
class(test1)
str(test1)
colnames(test1)
rownames(test1)
test2 <- data.frame(cbind(1:6))
class(test2)
str(test2)
colnames(test2)
rownames(test2)
newnames <- function(aa) {
names(aa) <- "a"
rownames(aa) <- LETTERS[1:6]
return(aa)
}
newnames(test1)
newnames(test2)
system
Closed
February 19, 2023, 2:10pm
3
This topic was automatically closed 42 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.