I would like to recode some strings into binary mode for codifing them into matrices, in R. Let's say I have the following strings in a data frame:
strings code
ABC 1
BCA 2
CAB 1
After extracting them I have the following strings:
"ABC" "BCA" "CAB"
And I would like to implement the next transformation:
A = 100
B = 010
C = 001
So that transforming "ABC" into the next matrix
100
010
001
And so, "BCA" into:
010
001
100
And "CAB" into:
001
100
010
And, after this transformation, getting a vector for "ABC" that is:
100010001
which represents ABC, an so on.
Basically, what I want to do is defining an algorithm with binary dictionary for letters characters so that it converts each letter into a binary sequence using R.
I've tried some aproaches but could not get a nice function...
Any help?