title: Tidy Data: Rename columns, get non-NA column names, then gather
body: <p>I've got a rather ugly bit of data to tidy up and need help! What my data look like now: </p>
  
  <pre><code>countries &lt;- c("Austria", "Belgium", "Croatia")
  
  df &lt;- tibble("age" = c(28,42,19, 67),
           "1_recreate_1"=c(NA,15,NA,NA), 
           "1_recreate_2"=c(NA,10,NA,NA), 
           "1_recreate_3"=c(NA,8,NA,NA),
           "1_recreate_4"=c(NA,4,NA,NA),
           "1_fairness" = c(NA, 7, NA, NA),
           "1_confidence" = c(NA, 5, NA, NA),
           "2_recreate_1"=c(29,NA,NA,30),
           "2_recreate_2"=c(20,NA,NA,24),
           "2_recreate_3"=c(15,NA,NA,15),
           "2_recreate_4"=c(11,NA,NA,9),
           "2_fairness" = c(4, NA, NA, 1),
           "2_confidence" = c(5, NA, NA, 4),
           "3_recreate_1"=c(NA,NA,50,NA), 
           "3_recreate_2"=c(NA,NA,40,NA), 
           "3_recreate_3"=c(NA,NA,30,NA),
           "3_recreate_4"=c(NA,NA,20,NA),
           "3_fairness" = c(NA,  NA, 2, NA),
           "3_confidence" = c(NA, NA, 2, NA),
           "overall" = c(3,3,2,5))    
  </code></pre>
  
  <p>What I need them to look like at the end (hard-coding it): </p>
  
  <pre><code>df &lt;- tibble(age = rep(c(28,42,19,67), each=4),
           country = rep(c("Belgium", "Austria", "Croatia", "Belgium"), each=4),
           recreate = rep(1:4, times=4),
           fairness = rep(c(4,7,2,1), each=4),
           confidence = rep(c(5,5,2,4), each=4),     
           allocation = c(29, 20, 15, 11,
                          15, 10, 8, 4,
                          50, 40, 30, 20, 
                          30, 24, 15, 9),
           overall = rep(c(3,3,2,5), each=4))
  </code></pre>
  
  <p>Steps to get there (I think!):   </p>
  
  <p><strong>1. Replace the starting numbers for those columns using my list of countries.</strong><br>
  The number that starts the string is the index in <code>countries</code>. In other words, <code>16_recreate_1</code> would correspond with the 16th country in the vector <code>countries</code>. I think the following code works (though am not sure it's exactly right): </p>
  
  <pre><code>for(i in length(countries):1){
      colnames(df) &lt;- str_replace(colnames(df), paste0(i,"_"), paste0(countries[i],"_"))
  }  
  </code></pre>
  
  <p><strong>2. Create a new variable called "country" by getting the name of the column(s) that is NOT NA for each row.</strong>  </p>
  
  <p>I tried a BUNCH of experimentation with <code>which.max</code> and <code>names</code>, but couldn't get it fully functional.</p>
  
  <p><strong>3. Create new variables (<code>recreate_1</code>...<code>recreate_4</code>) that grab the <code>[country_name]_recreate_1</code>...<code>[country_name]_recreate_4</code> value for each row, whatever country is non-NA for that person.</strong>  </p>
  
  <p>Maybe <code>rowSums</code> is the way to do this? </p>
  
  <p><strong>4. Make the data long instead of wide</strong>
  I think this is going to require <code>gather</code>, but I'm not sure how to gather from only the variables <code>country</code> and <code>recreate_1</code>...<code>recreate_4</code>.  </p>
  
  <p>I'm so sorry this is so complex. Tidyverse solutions are preferred but any help is <em>greatly</em> appreciated!</p>