what is the best way to join tables when key(s) are not normalized in R? -


Say, I have two tables, names and ages like this:

  & gt; ; Name is AA, B, C Jack 2D Daniel 3EFU 4F, G Bar & gt; Age of age 1B 13 2D 21 3E 244A 34 5F 100   

I am trying to use the key column in these two tables, which are present in both tables is. The challenge here is that the key column in the name table is not normalized. My question is, what is the best way to add the above two tables in a way that all the rows of the table of names are present and the associated table (like "race" table ) Are intact as the original?

  & gt;  
   & gt; dput (name) structure (list (key = structure (1: 4; label = c ("a, b, c", "d", "e", "f, g"), class = "factor") , Name = structure (C (4L, 2L, 3L, 1L), .Label = C ("bar", "Daniel", "afu", "jack"), class = "factor"). Name = c ("key", "name"), class = "data.frame", row.name = c (na, -4 l) gt; ("b", "d", "e", " F "," K ") (DBC), DPT (age) structure (list (key = structure (C (1 L, 2L, 3L, 5L, 4L). (" Key "," age ") , Class = "data.frame", line = name = = ("key", "age"), name = c (13L, 21L, 24L, 34L, 100L).) C. (NA, -5A ); gt; Dput (res) structure (list (key = structure (1: 4; label = c ("a, b, c", "d", "e", "f, g"), class = "factor"), name = structure (C (4L, 2L, 3L, 1L), .Lale = C ("bar", "Daniel", "FU", "jack"), class = "factor "), Age = C (13L, 21L, 24L, 100L)), name = c (" key "," name "," age "), class =" data.frame ", line.Name = C (NA, -4L))    

Let me introduce you to 2 Do not mind:

  Library for peer # vectors: Name and lieutenant; - as.data.frame (sapply (name, as.character), stringsfactor = F) Comma Separated IDs in Nominated List: (TMP and LT; - Set-name # $ Jack # [1] "A" "B "E" # # $ # [1] "D" ## $ FU # [1] StraussPlit (name $ key, ",", name)] "e" # # $ bar # [1] "F "G" # Long list for 2-column data frames: (TMP and LT; - Set-name (LDPE (TMP, matrix), C ("name", "key")) # Name key # 1 jack A # 2 Jack B # 3 Jack C # 4 Daniel D # 5 FU E # 6 times F # 7 times G # Income Join the data frame with the table (joining 1) & amp; # Add a separate key column from the original comma (to be included in 2) (- Join name, name, name = "name" (age, B, Type = "Inner")) - # Age Name Key # 1 13 Jack A, B, C # 2 21 Daniel D # 3 24 Fu E # 4 100 times F, G    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -