blob: 32c2f7631b0523aebaed8cba3f4cdc38d0c4cbff [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: ntile</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="R.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/languages/r.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head><body>
<table width="100%" summary="page for ntile {SparkR}"><tr><td>ntile {SparkR}</td><td align="right">R Documentation</td></tr></table>
<h2>ntile</h2>
<h3>Description</h3>
<p>Window function: returns the ntile group id (from 1 to n inclusive) in an ordered window
partition. For example, if n is 4, the first quarter of the rows will get value 1, the second
quarter will get 2, the third quarter will get 3, and the last quarter will get 4.
</p>
<h3>Usage</h3>
<pre>
## S4 method for signature 'numeric'
ntile(x)
ntile(x)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
<p>Number of ntile groups</p>
</td></tr>
</table>
<h3>Details</h3>
<p>This is equivalent to the <code>NTILE</code> function in SQL.
</p>
<h3>Note</h3>
<p>ntile since 1.6.0
</p>
<h3>See Also</h3>
<p>Other window_funcs: <code><a href="cume_dist.html">cume_dist</a></code>,
<code><a href="cume_dist.html">cume_dist</a></code>,
<code><a href="cume_dist.html">cume_dist,missing-method</a></code>;
<code><a href="dense_rank.html">dense_rank</a></code>, <code><a href="dense_rank.html">dense_rank</a></code>,
<code><a href="dense_rank.html">dense_rank,missing-method</a></code>;
<code><a href="lag.html">lag</a></code>, <code><a href="lag.html">lag</a></code>,
<code><a href="lag.html">lag,characterOrColumn-method</a></code>;
<code><a href="lead.html">lead</a></code>, <code><a href="lead.html">lead</a></code>,
<code><a href="lead.html">lead,characterOrColumn,numeric-method</a></code>;
<code><a href="percent_rank.html">percent_rank</a></code>, <code><a href="percent_rank.html">percent_rank</a></code>,
<code><a href="percent_rank.html">percent_rank,missing-method</a></code>;
<code><a href="rank.html">rank</a></code>, <code><a href="rank.html">rank</a></code>,
<code><a href="rank.html">rank</a></code>, <code><a href="rank.html">rank,ANY-method</a></code>,
<code><a href="rank.html">rank,missing-method</a></code>;
<code><a href="row_number.html">row_number</a></code>, <code><a href="row_number.html">row_number</a></code>,
<code><a href="row_number.html">row_number,missing-method</a></code>
</p>
<h3>Examples</h3>
<pre><code class="r">## Not run:
##D df &lt;- createDataFrame(mtcars)
##D
##D # Partition by am (transmission) and order by hp (horsepower)
##D ws &lt;- orderBy(windowPartitionBy(&quot;am&quot;), &quot;hp&quot;)
##D
##D # Get ntile group id (1-4) for hp
##D out &lt;- select(df, over(ntile(4), ws), df$hp, df$am)
## End(Not run)
</code></pre>
<hr><div align="center">[Package <em>SparkR</em> version 2.1.1 <a href="00Index.html">Index</a>]</div>
</body></html>