r extract top values from data frame

# Assuming you have a data frame named 'df' with a numeric column named 'value'

# Step 1: Use the order function to get the indices that would sort 'value' in descending order
sorted_indices <- order(df$value, decreasing = TRUE)

# Step 2: Use the head function to extract the top 'n' rows from the data frame
n <- 5  # Change this value to the desired number of top values
top_values <- df[sorted_indices[1:n], , drop = FALSE]