title: How can I use dplyr and magrittr to pipe a data manipulation into a function that requires a numeric vector?
body: <p>I am trying to use dplyr and magrittr to pipe a data manipulation into a function that wants a numeric vector as its input. Specifically, I'm hoping to have the result of my piping go into the ecdf() function (which generates an empirical cumulative distribution function from a vector). </p>
  
  <p>Here is what I would like to work:</p>
  
  <pre><code>x = rnorm(100)
  t = sample(c("A","B"), replace = TRUE)
  df = data.frame(x,t)
  df_ecdf = filter(df, x &gt; 0) %&gt;%
    filter(t == "A") %&gt;%
    select(x) %&gt;%
    as.vector() %&gt;%
    ecdf()
  </code></pre>
  
  <p>However, that doesn't work, because ecdf() gives the error: </p>
  
  <pre><code>Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) : 
    undefined columns selected
  </code></pre>
  
  <p>which makes sense, because the piping up through as.vector() doesn't actually result in a vector of data. It results in a list, that I don't know how to use piping to convert into a numeric vector. </p>
  
  <p>Any help would be much appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As answered by BrodieG below, the solution was to pipe into unlist before ecdf, and also didn't require parentheses (as per Ananda Mahto):</p>
  
  <pre><code>df_ecdf = filter(df, x &gt; 0) %&gt;%
    filter(t == "A") %&gt;%
    select(x) %&gt;%
    unlist %&gt;%
    ecdf
  </code></pre>