1

I have a simple problem that I cannot seem to figure out.

I have two datasets: df1 which contains observed values, and df2, which tells me whether or not those observed values should be marked as "included" (1) or "excluded" (0) from the analysis. However, I cannot figure out how to combine these data sets.

Here is some sample data:

​​df1 <- tibble(ID    = c(1, 1, 1, 1, 2, 2, 2, 2), 
              VISIT = c("a", "a", "b", "b", "a", "a", "b", "b"), 
              CONC  = c(1, 2, 4, 5, 1, 3, 2, 7))

df2 <- tibble(ID    = c(1, 1, 2, 2), 
              VISIT = c("a", "b", "a", "b"), 
              incl  = c(1, 1, 1, 0))

Here is the result that I need:

df1_result <- tibble(ID    = c(1, 1, 1, 1, 2, 2, 2, 2), 
                     VISIT = c("a", "a", "b", "b", "a", "a", "b", "b"), 
                     CONC  = c(1, 2, 4, 5, 1, 3, 2, 7),
                     incl  = c(1, 1, 1, 1, 1, 1, 0, 0))

As you can see, df2 informs me that the CONC values for Subject 2 at Visit B should not be included in the analysis.

jnguyen
  • 19
  • 2

0 Answers0