Try to search your question here, if you can't find : Ask Any Question Now ?

Is there a function to combine multiple primary keys info into table?

HomeCategory: stackoverflowIs there a function to combine multiple primary keys info into table?
Avatarjulie asked 1 month ago

I have two separate tables that have different primary keys and I need to join them together. One table provides the outcome and another table provides the ID of the people involved. Because there are multiple outcomes, and there are multiple people who could have similar outcomes, my table joins are not syncing up properly. I may be missing a step here and not thinking things logically, but any advice is greatly appreciated.

I originally tried joining the table by using this function I found:

rbind.all.columns <- function(x, y) {

    x.diff <- setdiff(colnames(x), colnames(y))
    y.diff <- setdiff(colnames(y), colnames(x))

    x[, c(as.character(y.diff))] <- NA

    y[, c(as.character(x.diff))] <- NA

    return(rbind(x, y))

However, all it does it provides me with the the outcome and the list of IDs.

Table 1:

145754  1738
145754  1756
145639  1738
145639  1756

df1 <- structure(list(EVENT = c(145754L, 145754L, 145639L, 145639L), ID = c(1738L, 1756L, 1738L, 1756L)), class = "data.frame", row.names = c(NA, -4L))

Table 2:

DEL     145754  Was given xxx med
INS     145754  
DEL     145639  Reported stomachache
INS     145639  

df2 <- structure(list(ENTRY = c("DEL", "INS", "DEL", "INS"), EVENT = c(145754L, 145754L, 145639L, 145639L), RESULT = c("Was given xxx med", "", "Reported stomachache", "")), class = "data.frame", row.names = c(NA, -4L))


ID          EVENT   RESULT
1738, 1756  145754  Was given xxx med
1738, 1756  145639  Reported stomachache
1 Answers
Best Answer
AvatarMannu answered 1 month ago
Your Answer

11 + 7 =

Popular Tags

WP Facebook Auto Publish Powered By :