read.table
returns a data frame (as per the documentation), which is not the same thing as a matrix.
As I’m sure you’re aware, your data had three columns, only the second two being numeric. When you convert the data frame from read.table
to a matrix with as.matrix
R coerces everything to a single type.
This is because matrices can only hold data from a single type, unlike data frames.
What you probably meant to do was:
matrixTable <- as.matrix(countsTable[,-1])
to remove the character column.
If you wanted to preserve the first column of data in the matrix, you would probably want to store them as row names:
rownames(matrixTable) <- countsTable[,1]
1
solved how to convert str to int?