r - How to collect the IDs of same group from one file and write it in second file? -
 I have two big txt files. 
 The first file contains two columns:  Groups  and  id  each group have different IDs. I want to collect all the IDs in each group in file A And I want to add them to B file. I have tried to use  total ()  and  merge () . But I was not sure that it was working correctly. Can anyone provide a good solution to this? 
The following is the structure of my files and desired output:
  File A Group ID A / B / CF1A / B / CF5A / B / Cf7a / b / cf6a / b / cf8e / ff1e / ff2e / ff4 . . File b group p / b / c ls a / b / c pr e / f sh e / f sh e / f gn. . Desired output: file B group ID PA / B / CF1 / F5 / F7 / F6 / F8 LS A / B / CF1 / F5 / F7 / F6 / F8 PR E / F R1 / R2 / R4 SHE / FR1 / R2 / R4 SHE / FR1 / R2 / R4 GN .     
  You can do this  dplyr  like this library 
   df.A & lt; - read.table (text = "group id a / b / cf1a / b / cf5a / b / cf7a / b / cf6a / b / cf8e / fr1 E / FR2E / FR4 ", Header = T, Sep =" ") DF. B & lt; - Read.table (text = "Group PA / B / C LS A / B / C PR E / F / E / FM / FGN", Header = T, Sep = "") Library (DP) TMP & Lt; - df.A%.% Group_by (Group)%.% Merge (ID = Paste (id, collapse = "/")) (TMP, DFB)  
   
 
  
Comments
Post a Comment