0

So I have an R data.frame with 2 columns. The first is a list of points/rankings of a specific football team, and the other is a list of corresponding teams, such that the first element of the first vector is a ranking and the first element of the second vector is the team with that ranking. For instance it could look something like this:


x = data.frame("r = data.frame("Points" = c(39,54,64), "Teams" = c("Jets","Titans", "Steelers"))




I now wanna sort the first vector in descending order, but I also need the second vector to still correspond to the correct elements. So for this simple example the result should look like:

r = data.frame("Points" = c(64,54,39), "Teams" = c("Steelers","Titans", "Jets"))

How could I do this in R? Im also wondering how I can swap two different entries in the first vector (rankings) and also swap the same corresponding entries in the second vector (teams).

Pame
  • 199
  • 8

0 Answers0