title: output the unique values across seven variables (R)
body: <p>I have a data frame that is based on a weekly food diary for survey participants. The data has been cleaned so that, for each food item, all the Monday intakes are recorded on fiMO, all the Tuesday intakes are recorded against fiTU, etc. The values are all numeric.</p>
  
  <p>What I want to do is to identify - and this could simply be to the R output window - the number of unique values across all seven days for the same food item. For example, if 1 was recorded in mo(nday) and also in we(dnesday), then I should only see 1 once. This is across all 4600 respondents.</p>
  
  <p>I tried</p>
  
  <pre><code> unique(Testdata[,2:8])
  </code></pre>
  
  <p>But it gave me the number of unique row as defined by the combination of all seven columns, not the number of unique values within all 7 columns taken as a whole.</p>
  
  <p>Using the fake data below, I wish to know the unique values in the set of seven days. I'm doing this for data cleaning, to ensure there are no unexpected values (e.g. out-of-range), hence why I do not care how many times each value occurs.</p>
  
  <pre><code> fakedays &lt;- data.frame(mo = c(ceiling(runif(100, min=-1, max=10))),
                          tu = c(ceiling(runif(100, min=-1, max=10))),
                          we = c(ceiling(runif(100, min=-1, max=10))),
                          th = c(ceiling(runif(100, min=-1, max=10))),
                          fr = c(ceiling(runif(100, min=-1, max=10))),
                          sa = c(ceiling(runif(100, min=-1, max=10))),
                          su = c(ceiling(runif(100, min=-1, max=10))))
  </code></pre>
  
  <p>I have looked at the answers <a href="https://stackoverflow.com/questions/7790732/unique-for-more-than-one-variable">here</a>, <a href="https://stackoverflow.com/questions/22963799/counting-unique-variables-within-a-unique-variables-r">here</a>, <a href="https://stackoverflow.com/questions/9944816/unique-on-a-dataframe-with-only-selected-columns">here</a>, and <a href="https://stackoverflow.com/questions/11369961/subset-with-unique-cases-based-on-multiple-columns">here</a> but they all relate to unique combinations of values across the columns of interest.</p>
  
  <p>I have 32 food items to clean, each with a week's data, hence why I do not wish to do this work single column at time.</p>