merge several values into one column

Hi all,

I'm going to be working on a study soon that will involve analyzing a common response variable across several conditions. Since the variable is worded slightly differently depending on the experimental condition though, each condition gets their own version of it....which means there will be up to 12 copies of it in the data set, and the people in (e.g., condition A) will only be able to see and mark variable A that matches their condition; anyone assigned to B or C will have NA's for their responses.

It will look something like this:

example_data=tribble(~A,~B,~C,
            1,NA,NA,
            2,NA,NA,
            3,NA,NA,
            NA,4,NA,
            NA,5,NA,
            NA,6,NA,
            NA,NA,7,
            NA,NA,8,
            NA,NA,9)

I need to figure out a way to collapse all of them into a single column. Ideally, I'd like a way to transform the above data into this:


ideal_data=tribble(
  ~A,
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9)
example_data %>%
  mutate(collapsed = 
           pmin(A,
                B,
                C,
                na.rm = TRUE))
1 Like

I've never had a solution presented so fast. Thank you so much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.