title: R Parsing a data set to both get rid of rows on certain value as well as turn make columns based on a character
body: <p>I am having issues trying to delete rows from a dataset that seems to only have one column - thus it is like a column vector.  I am trying to do two things, it doesn't matter which first (to me).  Here is a sample of the data:</p>
  
  <p><em>republican,n,y,n,y,y,y,n,n,n,n,n,y,y,y,n,y<br>
  democrat,y,y,y,n,n,n,y,y,y,n,n,n,n,n,?,?</em></p>
  
  <p>I am bringing in the data like this:</p>
  
  <pre><code>sampledata &lt;- read.table("house-votes-84.data",)
  </code></pre>
  
  <p>but I want turn the string of data for each rows in to a column and give that column a name.  Now I know I can name things by the following:  </p>
  
  <pre><code>names(sampledata) &lt;- c("col1" ...., "col17")
  </code></pre>
  
  <p>but can only do so if there are 17 columns.  Each of the would be columns are separated by a comma.</p>
  
  <p>Second, I am trying rid myself of the rows with a questions mark ?</p>
  
  <p>What I have tried?</p>
  
  <p>I have tried things such as (with my data called sample data):</p>
  
  <pre><code>sampledata[apply(sampledata[, -1], MARGIN = 1, function(x) all(x != "?")), ]  
  </code></pre>
  
  <p>That doesn't work (and I am guessing because there is only one Column so that Margin would have to be something that each of the columns would be looked through (I tried -1 for Margin but to no avail)</p>
  
  <p>I have tried changing the ?'s to NA's and use the </p>
  
  <pre><code>na.omit(sampledata)
  </code></pre>
  
  <p>That doesn't work either.</p>
  
  <p>I have tried the parsing by commas such as</p>
  
  <pre><code>splitting &lt;- strsplit(as.character(sampledata$V1), split=",")
  </code></pre>
  
  <p>where V1 is the single column name.  That is the most interesting result as I get</p>
  
  <p>435 of the following (there are 435 rows of data)</p>
  
  <pre><code>_[[435]]_  
  _ [1] "republican" "n"          "y"          "n"          "y"        _  
  _ [6] "y"          "y"          "n"          "n"          "n"       _
  _[11] "y"          "n"          "y"          "y"          "y"  _
  _[16] "NA"         "n"_
  </code></pre>
  
  <p>But when I try to change the name's:
  Error in</p>
  
  <pre><code>names(sampledata) &lt;- c("col1", "col2", "col3", "col4", "col5",  : 'names' attribute [17] must be the same length as the vector [1]
  </code></pre>
  
  <p>I have tried other things, such as trying to turn it in to a dataset - this however seems to turn all the values in to numbers that look to be randomized (not something such as 0, 1, or 99 for the ?, but values even up to 100, maybe more)</p>
  
  <p>I am just trying to get the data in the correct format so that I can run a regression on the samples that don't have question marks.</p>
  
  <p>The sites that I have had best luck with are Stack Exchange Also and are here:</p>
  
  <p><a href="https://stackoverflow.com/questions/9856632/subset-rows-with-all-any-columns-larger-than-a-specific-value">subset rows with all / any columns larger than a specific value</a></p>
  
  <p>And Here:</p>
  
  <p><a href="https://stackoverflow.com/questions/8464312/r-converting-comma-separated-entry-to-columns">Convert comma separated entry to columns</a></p>
  
  <p>With the first, I can get it to work but even with that I am generating the data in the 3 column's in the code itself - I can't seem to get the same code to work on my ?'s (although I can get the program to remove the rows with question marks using:</p>
  
  <pre><code> X &lt;- data.frame(Variable1=c(11,"?",12,15),Variable2=c(2,3,1,4))  
  X[X$Variable1!="?", ]  
  </code></pre>
  
  <p>I have been trying to figure out a way to make the code, row by row do the same thing for the imported data as I am pulling it in as a data.frame also (I realize I only have 1 column, and the column is called V1, so I changed the code likewise to </p>
  
  <pre><code>X$V1  
  
  sampledata &lt;- read.table("house-votes-84NaN.data.txt")
  splitdat = do.call("rbind", strsplit(sampledata$V1, ","))
  </code></pre>
  
  <p>But I get </p>
  
  <pre><code>**Error in strsplit(sampledata$V1, ",") : non-character argument**
  </code></pre>
  
  <p>I do realize that I need more arguments (I think) in read.table as they have some more - but I don't understand what needs to go in.</p>
  
  <p>Any help would be very much appreciated.</p>
  
  <p>Thank you,</p>
  
  <p>Brian</p>