title: Check dataframe with different functions (dplyr)
body: <p>I am trying to write some functions that take a dataframe and check whether certain variables fulfill certain criteria. For each check I would like to create a new variable &quot;check_&quot; giving the result of the check. Unfortunately, I still struggle to get it right. Can someone help me?</p>
  <pre class="lang-r prettyprint-override"><code># Some sample data
  dat &lt;- data.frame(Q1_1 = c(1, 1, 2, 5, 2, 1),
                    Q1_2 = c(1, 2, 3, 5, 1, 3),
                    Q1_3 = c(4, 3, 3, 5, 1, 3),
                    Q1_4 = c(4, 2, 2, 5, 1, 2),
                    Q1_5 = c(2, 2, 1, 5, 5, 4),
                    Q2_1 = c(1, 2, 1, 2, 1, 2),
                    Q2_2 = c(2, 1, 1, 1, 2, 1),
                    Q2_3 = c(1, 1, 1, 2, 2, 1),
                    age = c(22,36,20,27,13, 9))
  
  
  # Some checker-functions
  
  check_age &lt;- function(.df, agevar = &quot;age&quot;){
    #' Function should check if the age value is within a certain range
    #' and create a new variable &quot;check_age&quot; giving the result of the check
  
    .df %&gt;% mutate(check_age = ifelse(age &gt; 100, FALSE, TRUE),
                   check_age = ifelse(age &lt; 4, FALSE, TRUE))
    ???
  }
  
  check_sameAnswers &lt;- function(.df, varname = &quot;Q1_&quot;){
    #' Function should check whether all sub Of a question (e.g. Q1_1 to Q1_5) have the
    #' same values and create a new variable &quot;check_sameAnswers&quot; giving the result of the check.
    #' It should be TRUE if Q1_1, Q1_2, ... have the value 5 for example, otherwise FALSE
    
    ???
  }
  
  
  # Apply checker functions to dataframe in &quot;dplyr-style&quot;
  dat &lt;- dat %&gt;% 
            check_age(agevar = &quot;age&quot;) %&gt;%
            check_sameAnswers(varname = &quot;Q1_&quot;)
  </code></pre>