I would like to convert a matrix of values ββto a matrix of "bits".
I was looking for solutions and found this one that seems to be part of the solution. I will try to explain what I am looking for. I have a matrix like
> x<-matrix(1:20,5,4) > x [,1] [,2] [,3] [,4] [1,] 1 6 11 16 [2,] 2 7 12 17 [3,] 3 8 13 18 [4,] 4 9 14 19 [5,] 5 10 15 20
which I would like to convert to
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 2 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 3 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 4 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 5 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
therefore, for each value in row a "1" in the corresponding column.
If i use
> table(sequence(length(x)),t(x)) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 5 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 9 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 13 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 17 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
this is close to what I'm looking for, but returns a string for each value.
I would only need to combine all the values ββfrom one row into one row. Because the
> table(x) x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
gives alls values ββof the whole table, so what I need to do to get the values ββfor each row.
matrix r
Kurt ludikovsky
source share