title: Identifying rows in data.frame with only NA values in R
body: <p>I have a <code>data.frame</code> with 15,000 observations of 34 ordinal and <code>NA</code> variables. I am performing clustering for a market segmentation study and need the rows with only <code>NAs</code> removed. After taking out the userID I got an error message saying to omit 2099 rows with only <code>NAs</code> before clustering. </p>
  
  <p>I found a link for removing rows with all <code>NA</code> values, but I need to identify which of the 2099 rows have all NA values. Here the link for the discussion removing rows with all <code>NA</code> values: <a href="https://stackoverflow.com/questions/4862178/remove-rows-with-nas-in-data-frame">Remove Rows with NAs in data.frame</a></p>
  
  <p>Here's a sample of the first five observations from six variables:</p>
  
  <pre><code>&gt; head(Store2df, n=5)
    RowNo      Age Gender HouseholdIncome MaritalStatus PresenceofChildren
  1     1     &lt;NA&gt;   Male            &lt;NA&gt;          &lt;NA&gt;               &lt;NA&gt;
  2     2    45-54 Female            &lt;NA&gt;          &lt;NA&gt;               &lt;NA&gt;
  3     3     &lt;NA&gt;   &lt;NA&gt;            &lt;NA&gt;          &lt;NA&gt;               &lt;NA&gt;
  4     4     &lt;NA&gt;   &lt;NA&gt;            &lt;NA&gt;          &lt;NA&gt;               &lt;NA&gt;
  5     5    45-54 Female        75k-100k       Married                Yes
  #Making a vector
  &gt; Vector1 &lt;- Store2df$RowNo 
  #Taking out RowNo column
  &gt; Store2df$RowNo &lt;- NULL
  </code></pre>
  
  <p><strong>EDIT:</strong> I put the results in a object, but found that the code made an extra column. Clicking in RStudio's environment, an extra column called row.names was created labeling each row with the original row name. A couple thousand rows were deleted and the new column labeled the new rows with the old row number. However when looking at the head of the new object, I did not see the row label. Why does the row.names label show in the environment, but not when I view the head?</p>
  
  <pre><code>#Remove all rows with only NA values
  &gt; Store2df &lt;- Store2[!!rowSums(!is.na(Store2)),]
  #View head of store2df
  &gt; head(Store2df)
      Age Gender HouseholdIncome MaritalStatus PresenceofChildren
  1  &lt;NA&gt;   Male            &lt;NA&gt;          &lt;NA&gt;               &lt;NA&gt;
  2 45-54 Female            &lt;NA&gt;          &lt;NA&gt;               &lt;NA&gt;
  5 45-54 Female        75k-100k       Married                Yes
  6 25-34   Male        75k-100k       Married                 No
  7 35-44 Female       125k-150k       Married                Yes
  8 55-64   Male        75k-100k       Married                 No
  </code></pre>
  
  <p><strong>EDIT 2:</strong> I put in the row number/userID column to keep track of the number of users. To perform the operation for removing all <code>NA</code>s, I took out the first column. Now I need to keep track of the users I removed. I have a list of over 2000 rows that had all <code>NA</code> values, I don't want to create an index manually putting in each row.  </p>
  
  <p><strong>Question:</strong> How do I remove the emails that the missing data corresponded to? </p>
  
  <pre><code>&gt; #First six rows of the column RowNo
  &gt; head(Store2df$RowNo)
  [1] 1 2 3 4 5 6
  </code></pre>
  
  <p>I want 2099 rows deleted in the Store2df <code>data.frame</code> with the <code>RowNo</code> included. Here's the script identifying which rows are all empty in the Store2df <code>data.frame</code> without <code>RowNo</code>.</p>
  
  <pre><code>&gt; which(rowSums(is.na(Store2df))==ncol(Store2df))
  </code></pre>
  
  <p>Showing the first 6 rows, row number 3 and 4 are deleted. </p>
  
  <pre><code>&gt; head(Store2df$RowNo)
  [1] 1 2 5 6 7 8
  </code></pre>
  
  <p><strong>There are 4 steps I want to complete:</strong></p>
  
  <p>1) Take out <code>RowNo</code> column in Store2df <code>data.frame</code> and save as separate vector </p>
  
  <p>2) Delete rows with all <code>NA</code> values in Store2df <code>data.frame</code></p>
  
  <p>3) Delete same rows in Store2new1 <code>vector</code> as Store2df <code>data.frame</code></p>
  
  <p>4) Combine <code>vector</code> and <code>data.frame</code> with <code>vector</code> matching the <code>data.frame</code></p>