filter

filter returns the rows of a DataFrame that matches the given condition.

Syntax:

  • filter(DataFrame, condition)

Parameters:

  • DataFrame: Any SparkR DataFrame
  • condition: Condition to filter on. This may either be a Column expression or a string containing a SQL statement

Output:

  • SparkR DataFrame
# Create SparkR DataFrame
df <- createDataFrame(sqlContext, mtcars)
head(df)
# Filter using Column Expression
filtered <- filter(df, df$cyl == 6)
collect(filtered)
# Alternative Syntax
# Filter using SQL statement strings
filtered2 <- filter(df, "cyl = 6")
collect(filtered2)