blob: b60cb8bf3c50147e08a25562d6711bcaf24e26c1 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Subset</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 subset {SparkR}"><tr><td>subset {SparkR}</td><td style="text-align: right;">R Documentation</td></tr></table>
<h2>Subset</h2>
<h3>Description</h3>
<p>Return subsets of SparkDataFrame according to given conditions
</p>
<h3>Usage</h3>
<pre>
subset(x, ...)
## S4 method for signature 'SparkDataFrame,numericOrcharacter'
x[[i]]
## S4 replacement method for signature 'SparkDataFrame,numericOrcharacter'
x[[i]] &lt;- value
## S4 method for signature 'SparkDataFrame'
x[i, j, ..., drop = F]
## S4 method for signature 'SparkDataFrame'
subset(x, subset, select, drop = F, ...)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
<p>a SparkDataFrame.</p>
</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
<p>currently not used.</p>
</td></tr>
<tr valign="top"><td><code>i, subset</code></td>
<td>
<p>(Optional) a logical expression to filter on rows.
For extract operator [[ and replacement operator [[&lt;-, the indexing parameter for
a single Column.</p>
</td></tr>
<tr valign="top"><td><code>value</code></td>
<td>
<p>a Column or an atomic vector in the length of 1 as literal value, or <code>NULL</code>.
If <code>NULL</code>, the specified Column is dropped.</p>
</td></tr>
<tr valign="top"><td><code>j, select</code></td>
<td>
<p>expression for the single Column or a list of columns to select from the
SparkDataFrame.</p>
</td></tr>
<tr valign="top"><td><code>drop</code></td>
<td>
<p>if TRUE, a Column will be returned if the resulting dataset has only one column.
Otherwise, a SparkDataFrame will always be returned.</p>
</td></tr>
</table>
<h3>Value</h3>
<p>A new SparkDataFrame containing only the rows that meet the condition with selected
columns.
</p>
<h3>Note</h3>
<p>[[ since 1.4.0
</p>
<p>[[&lt;- since 2.1.1
</p>
<p>[ since 1.4.0
</p>
<p>subset since 1.5.0
</p>
<h3>See Also</h3>
<p><a href="withColumn.html">withColumn</a>
</p>
<p>Other SparkDataFrame functions:
<code><a href="SparkDataFrame.html">SparkDataFrame-class</a></code>,
<code><a href="summarize.html">agg</a>()</code>,
<code><a href="alias.html">alias</a>()</code>,
<code><a href="arrange.html">arrange</a>()</code>,
<code><a href="as.data.frame.html">as.data.frame</a>()</code>,
<code><a href="attach.html">attach,SparkDataFrame-method</a></code>,
<code><a href="broadcast.html">broadcast</a>()</code>,
<code><a href="cache.html">cache</a>()</code>,
<code><a href="checkpoint.html">checkpoint</a>()</code>,
<code><a href="coalesce.html">coalesce</a>()</code>,
<code><a href="collect.html">collect</a>()</code>,
<code><a href="columns.html">colnames</a>()</code>,
<code><a href="coltypes.html">coltypes</a>()</code>,
<code><a href="createOrReplaceTempView.html">createOrReplaceTempView</a>()</code>,
<code><a href="crossJoin.html">crossJoin</a>()</code>,
<code><a href="cube.html">cube</a>()</code>,
<code><a href="dapplyCollect.html">dapplyCollect</a>()</code>,
<code><a href="dapply.html">dapply</a>()</code>,
<code><a href="describe.html">describe</a>()</code>,
<code><a href="dim.html">dim</a>()</code>,
<code><a href="distinct.html">distinct</a>()</code>,
<code><a href="dropDuplicates.html">dropDuplicates</a>()</code>,
<code><a href="nafunctions.html">dropna</a>()</code>,
<code><a href="drop.html">drop</a>()</code>,
<code><a href="dtypes.html">dtypes</a>()</code>,
<code><a href="exceptAll.html">exceptAll</a>()</code>,
<code><a href="except.html">except</a>()</code>,
<code><a href="explain.html">explain</a>()</code>,
<code><a href="filter.html">filter</a>()</code>,
<code><a href="first.html">first</a>()</code>,
<code><a href="gapplyCollect.html">gapplyCollect</a>()</code>,
<code><a href="gapply.html">gapply</a>()</code>,
<code><a href="getNumPartitions.html">getNumPartitions</a>()</code>,
<code><a href="groupBy.html">group_by</a>()</code>,
<code><a href="head.html">head</a>()</code>,
<code><a href="hint.html">hint</a>()</code>,
<code><a href="histogram.html">histogram</a>()</code>,
<code><a href="insertInto.html">insertInto</a>()</code>,
<code><a href="intersectAll.html">intersectAll</a>()</code>,
<code><a href="intersect.html">intersect</a>()</code>,
<code><a href="isLocal.html">isLocal</a>()</code>,
<code><a href="isStreaming.html">isStreaming</a>()</code>,
<code><a href="join.html">join</a>()</code>,
<code><a href="limit.html">limit</a>()</code>,
<code><a href="localCheckpoint.html">localCheckpoint</a>()</code>,
<code><a href="merge.html">merge</a>()</code>,
<code><a href="mutate.html">mutate</a>()</code>,
<code><a href="ncol.html">ncol</a>()</code>,
<code><a href="nrow.html">nrow</a>()</code>,
<code><a href="persist.html">persist</a>()</code>,
<code><a href="printSchema.html">printSchema</a>()</code>,
<code><a href="randomSplit.html">randomSplit</a>()</code>,
<code><a href="rbind.html">rbind</a>()</code>,
<code><a href="rename.html">rename</a>()</code>,
<code><a href="repartitionByRange.html">repartitionByRange</a>()</code>,
<code><a href="repartition.html">repartition</a>()</code>,
<code><a href="rollup.html">rollup</a>()</code>,
<code><a href="sample.html">sample</a>()</code>,
<code><a href="saveAsTable.html">saveAsTable</a>()</code>,
<code><a href="schema.html">schema</a>()</code>,
<code><a href="selectExpr.html">selectExpr</a>()</code>,
<code><a href="select.html">select</a>()</code>,
<code><a href="showDF.html">showDF</a>()</code>,
<code><a href="show.html">show</a>()</code>,
<code><a href="storageLevel.html">storageLevel</a>()</code>,
<code><a href="str.html">str</a>()</code>,
<code><a href="summary.html">summary</a>()</code>,
<code><a href="take.html">take</a>()</code>,
<code><a href="toJSON.html">toJSON</a>()</code>,
<code><a href="unionByName.html">unionByName</a>()</code>,
<code><a href="union.html">union</a>()</code>,
<code><a href="unpersist.html">unpersist</a>()</code>,
<code><a href="withColumn.html">withColumn</a>()</code>,
<code><a href="withWatermark.html">withWatermark</a>()</code>,
<code><a href="with.html">with</a>()</code>,
<code><a href="write.df.html">write.df</a>()</code>,
<code><a href="write.jdbc.html">write.jdbc</a>()</code>,
<code><a href="write.json.html">write.json</a>()</code>,
<code><a href="write.orc.html">write.orc</a>()</code>,
<code><a href="write.parquet.html">write.parquet</a>()</code>,
<code><a href="write.stream.html">write.stream</a>()</code>,
<code><a href="write.text.html">write.text</a>()</code>
</p>
<p>Other subsetting functions:
<code><a href="filter.html">filter</a>()</code>,
<code><a href="select.html">select</a>()</code>
</p>
<h3>Examples</h3>
<pre><code class="r">## Not run:
##D # Columns can be selected using [[ and [
##D df[[2]] == df[[&quot;age&quot;]]
##D df[,2] == df[,&quot;age&quot;]
##D df[,c(&quot;name&quot;, &quot;age&quot;)]
##D # Or to filter rows
##D df[df$age &gt; 20,]
##D # SparkDataFrame can be subset on both rows and Columns
##D df[df$name == &quot;Smith&quot;, c(1,2)]
##D df[df$age %in% c(19, 30), 1:2]
##D subset(df, df$age %in% c(19, 30), 1:2)
##D subset(df, df$age %in% c(19), select = c(1,2))
##D subset(df, select = c(1,2))
##D # Columns can be selected and set
##D df[[&quot;age&quot;]] &lt;- 23
##D df[[1]] &lt;- df$age
##D df[[2]] &lt;- NULL # drop column
## End(Not run)
</code></pre>
<hr /><div style="text-align: center;">[Package <em>SparkR</em> version 2.4.7 <a href="00Index.html">Index</a>]</div>
</body></html>