Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

In my data frame, I am having some single observations and some double observations. In the situation of double observations in x, I want to pick the row with the lower 'y' value so that in future I can remove that row.

ex <- data.frame('x'= c(1:5, 1:3,5:6), 'y'= c(70,73,72,49,60,14,50,46,13,29))

The original data frame is:

enter image description here

And this is what I want:

 enter image description here

1 Answer

0 votes
by (107k points)

If you want to sort the 'y' on the basis of the lower value then in that case in R Programming, you can use the aggregate() as this will help you in finding the largest number per group:

aggregate(y ~ x, ex, max)

#  x  y

#1 1 70

#2 2 73

#3 3 72

#4 4 49

#5 5 60

#6 6 29

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...