limit

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

Syntax:

  • limit(DataFrame, num)

Parameters:

  • DataFrame: Any SparkR DataFrame
  • num: Integer

Output:

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