[R] Matched Items in rows + issue with writing a table

abo dalash abo_dlsh at hotmail.com
Fri May 12 01:16:34 CEST 2017


Hi All ..,


I have a table called "x444" and I would like to create a new column contains the matched items in each row between column w & r . I used match()function as below but this does not return the results I want because of 2 issues. The 1st one is that this gives the row number of shared items while I want to see the item itself (e.g. in the table below, I want to see cyp2 instead of the row number 2). The 2nd issue is that I need to know matched items considering every item in the row instead of the entire row. For example, the item cyp3 is a matched item in the first row between columns w & r. The same applies for c6 in row 3. These don't appear in the results below.



>x444
               w         r
1 cyp3,cyp7     cyp2, cyp1,cyp3
2         cyp2      cyp2
3   c1,c3,c6       c6,c8,c5


> r = c(match(x444$w,X444$r))
> r
[1] NA  2 NA



The desired output should be like this :-

                w             r                             matched items
1 cyp3,cyp7     cyp2, cyp1,cyp3             cyp3
2         cyp2      cyp2                                  cyp2
3   c1,c3,c6       c6,c8,c5                          c6


The second issue is that when I write a table produced in R as follows :

write.table(MyTable,file="MyTable.txt", sep = "\t", quote = F, row.names = F)

and the read this txt. file in excel, some items from column B appears in Column A and some empty rows also appear?.

Could you please guide me about the mistakes I have done and suggest
some solutions?

Regards

	[[alternative HTML version deleted]]



More information about the R-help mailing list