i am a beginner in R. I have a data set called data_mat. it has only binary variables i.e. all variables have 0 or 1 as values. It look like this:
Elderflower high low medium
[1,] 0 1 0 0
[2,] 0 1 0 0
[3,] 0 1 0 0
[4,] 0 1 0 0
it is a numeric matrix. on adding 3 more columns (which are again binary in nature) into it using following code, it no more remains numeric:
data_mat<-cbind(data_mat,datam[,c(5:6,9)])
post executing above code, data now looks like this:
Elderflower high low medium Sugar Chewy Content
[1,] "0" "1" "0" "0" "1" "1" "1"
[2,] "0" "1" "0" "0" "0" "0" "1"
[3,] "0" "1" "0" "0" "1" "1" "1"
[4,] "0" "1" "0" "0" "0" "0" "1"
in order to convert this matrix into numeric i ran following code:
data11<-matrix(as.numeric(unlist(data_mat,use.names =
TRUE)),nrow=nrow(data_mat))
with this my data remains a numeric matrix but column names are gone. it now looks like this:
[,59] [,60]
[1,] 1 1
[2,] 0 1
[3,] 1 1
[4,] 0 1
Kindly suggest how do i tackle this problem? Motive is to get numeric matrix with column names intact post adding new columns to existing numeric matrix.