Create a presence absence matrix in R for gene data
1
2
Entering edit mode
8.4 years ago
natasha ▴ 110

Hi

I am new to R and would like to create a presence absence matrix for my gene data.

My data at the moment looks like this;

 Isolate    1        2       3        4
 Gene1     N/A     Vp_2003  Vp_2003  Vp_2004
 Gene2    Vp_4590  N/A      N/A      N/A
 Gene3    Vp_3333  Vp_3333  Vp_3333  Vp_3333

....

I would like Vp values to be replaced with 1's and N/A to be replaced with 0's.

Many thanks

R • 3.6k views
ADD COMMENT
3
Entering edit mode
8.4 years ago
Michael 55k

given mat contains your data as character matrix

mat != "N/A"

gives you a logical matrix, that should be ok for binary clustering methods in R.

or

 dist(mat != "N/A", method = "binary" )

gives you the distances directly.

ADD COMMENT
2
Entering edit mode

and (mat != "N/A")*1 will get 0s and 1s

ADD REPLY
0
Entering edit mode

Thank you, this worked perfectly

ADD REPLY

Login before adding your answer.

Traffic: 2497 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6