limitΒΆ

limit returns the first NUM rows of a SparkDataFrame as a SparkDataFrame. This is useful if you require only a subset of your original SparkDataFrame.

Syntax:

  • limit(SparkDataFrame, num)

Parameters:

  • SparkDataFrame: Any SparkDataFrame
  • num: Integer

Output:

  • SparkDataFrame
require(SparkR)

# Create SparkDataFrame
df <- createDataFrame(mtcars)
head(df)
# Limit resulting SparkDataFrame to 3 rows
small_df <- limit(df ,3)
collect(small_df)
# limit() returns a SparkDataFrame
str(small_df)