and (mat != "N/A")*1 will get 0s and 1s
• 1 views
•
link
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
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.
Log in to answer this question.