Skip to content

change factor to mtrix

3 messages · Gallon Li, Jim Lemon, Peter Dalgaard

#
On 06/12/2013 05:47 PM, Gallon Li wrote:
Hi Gallon,
If you want exactly the output shown above, it is not trivial. You could 
convert ff to a factor, then use as.numeric to get:

a = 1
b = 2
c = 3

If you subtract one and display the numbers in two digits of binary:

a = 00
b = 01
c = 10

Then if you apply as.character and strsplit, you can get:

a = "0" "0"
b = "0" "1"
c = "1" "0"

Finally, as.numeric will give you numbers. This does not produce the 
numbers above, but it might give you an idea of what to do.

Jim
#
On Jun 12, 2013, at 09:47 , Gallon Li wrote:

            
Maybe not fast, but quick:
fffb fffc
1    0    0
2    0    0
3    1    0
4    1    0
5    0    1
6    0    1

Possibly faster, skipping some "red tape":
b c
a 0 0
b 1 0
c 0 1
b c
a 0 0
a 0 0
b 1 0
b 1 0
c 0 1
c 0 1