How to Find the Second and Third Lowest Values in Data Frame Column in R

To find the second and third lowest values in R Data Frame Column, you can use the “sort()” method.

df <- data.frame(
  name = c("A", "B", "C", "D", "E", "F", "G"),
  value = c(51, 12, 41, 21, 20, 81, 11)
)

# Second and third lowest values
sorted_values_asc <- sort(df$value, decreasing = FALSE)
second_lowest_value <- sorted_values_asc[2]
third_lowest_value <- sorted_values_asc[3]

cat("Second lowest value in data frame column:", second_lowest_value, "\n")
cat("Third lowest value in data frame column:", third_lowest_value, "\n")

Output

Second lowest value in data frame column: 12

Third lowest value in data frame column: 20

That’s it!

Leave a Comment