0
votes

enter image description hereI'm beginner so I have a big problem.T.T

let me show you my script

test_call = read_excel(path="E:\\matrix.xlsx", sheet="Sheet1", col_names=TRUE)
df <-  data.frame(test_call)
df2 <-as.data.frame.matrix(table(df))
n <- nrow(df2)
m <- ncol(df2)
rownames(A) <- 1:n
colnames(A) <- 1:m
B <- rbind(cbind(matrix(0,n,n),df2),cbind(t(df2),matrix(0,m,m)))

First question is when I ran "n <- nrow(df2)& m <- ncol(df2)" I got the warning message like "length of 'dimnames' 1 not equal to array extent" I think I count the number of row and put those values into my row&column's name I don't know why. Second question is I got the message "length of 'dimnames' 1 not equal to array extent" when i run "B <- rbind(cbind(matrix(0,n,n),df2),cbind(t(df2),matrix(0,m,m)))" How can i solve this problem??

1

1 Answers

1
votes

Not entirely sure what are you trying to do there, without seeing what is your data and what is your endgame.

What is matrix A?

But is it possible that something like this would work for you?

test_call = read_excel(path="E:\\matrix.xlsx",
                       sheet="Sheet1", 
                       col_names=TRUE)
df <-  data.frame(test_call)
df2 <-as.matrix(table(df))
n <- nrow(df2)
m <- ncol(df2)
rownames(df2) <- 1:n
colnames(df2) <- 1:m
B <- rbind(cbind(matrix(0,n,n),df2),cbind(t(df2),matrix(0,m,m)))

Depending on how you want to call your columns, you can also do something like:

rownames(df2) <- NULL
colnames(df2) <- NULL
B <- rbind(cbind(matrix(0,n,n),df2),cbind(t(df2),matrix(0,m,m)))
colnames(B) <- 1:(n+m)
rownames(B) <- 1:(n+m)