
Last chance! 50% off unlimited learning
Sale ends in
Return subsets of SparkDataFrame according to given conditions
subset(x, ...)# S4 method for SparkDataFrame,numericOrcharacter
[[(x, i)
# S4 method for SparkDataFrame,numericOrcharacter
[[(x, i) <- value
# S4 method for SparkDataFrame
[(x, i, j, ..., drop = F)
# S4 method for SparkDataFrame
subset(x, subset, select, drop = F, ...)
a SparkDataFrame.
currently not used.
(Optional) a logical expression to filter on rows. For extract operator [[ and replacement operator [[<-, the indexing parameter for a single Column.
a Column or an atomic vector in the length of 1 as literal value, or NULL
.
If NULL
, the specified Column is dropped.
expression for the single Column or a list of columns to select from the SparkDataFrame.
if TRUE, a Column will be returned if the resulting dataset has only one column. Otherwise, a SparkDataFrame will always be returned.
A new SparkDataFrame containing only the rows that meet the condition with selected columns.
Other SparkDataFrame functions: SparkDataFrame-class
,
agg
, arrange
,
as.data.frame
, attach
,
cache
, coalesce
,
collect
, colnames
,
coltypes
,
createOrReplaceTempView
,
crossJoin
, dapplyCollect
,
dapply
, describe
,
dim
, distinct
,
dropDuplicates
, dropna
,
drop
, dtypes
,
except
, explain
,
filter
, first
,
gapplyCollect
, gapply
,
getNumPartitions
, group_by
,
head
, histogram
,
insertInto
, intersect
,
isLocal
, join
,
limit
, merge
,
mutate
, ncol
,
nrow
, persist
,
printSchema
, randomSplit
,
rbind
, registerTempTable
,
rename
, repartition
,
sample
, saveAsTable
,
schema
, selectExpr
,
select
, showDF
,
show
, storageLevel
,
str
, take
,
union
, unpersist
,
withColumn
, with
,
write.df
, write.jdbc
,
write.json
, write.orc
,
write.parquet
, write.text
# NOT RUN {
# Columns can be selected using [[ and [
df[[2]] == df[["age"]]
df[,2] == df[,"age"]
df[,c("name", "age")]
# Or to filter rows
df[df$age > 20,]
# SparkDataFrame can be subset on both rows and Columns
df[df$name == "Smith", c(1,2)]
df[df$age %in% c(19, 30), 1:2]
subset(df, df$age %in% c(19, 30), 1:2)
subset(df, df$age %in% c(19), select = c(1,2))
subset(df, select = c(1,2))
# Columns can be selected and set
df[["age"]] <- 23
df[[1]] <- df$age
df[[2]] <- NULL # drop column
# }
Run the code above in your browser using DataLab