I want a 7*17 matrix.
row names are from 2:8 ( first row name to be 2, 2nd row to be 3 and ...)
colnames are 4:17 ( first column has name 4 and 2nd column has name 5 and ... )
matrix elements are filled such that mat[i,j] = rowname of ith row * colnames of jth col.
I get error with what I m attempting:
mat <- matrix(0, nrow = 7, ncol = 17 , byrow = TRUE)
for (rr in 2:8) {
row.names(mat)[rr-1] <- paste('class', rr, sep='.')
for(cc in 4:20){
mat[rr-1,cc-3] <- rr*cc
colnames(mat)[cc] <- paste('count', cc, sep='.')
}
}
this is the error:
Error in dimnames(x) <- dn : length of 'dimnames' [1] not equal to array
how can I fix this.
dataframe
with one column containing names? – SNR