Reputation: 1
this may be a little simple but i cannot manage to do it !
I've got a dataframe that looks like this:
Fruits gr
Apples Oranges 4
Oranges Lemons 5
Lemons Apples 2
And I want it to look like this:
Fruits gr
Apples Apples 2
Oranges Oranges 4
Lemons Lemons 5
So to reorder the twos columns according to the rows. Also Knowing that i have a lot of rows so i cannot move it "manually".
structure(list(Fruits = structure(1:3, .Label = c("apple", "lemons",
"oranges"), class = "factor"), gr = c(4, 5, 2)), .Names = c("Fruits",
"gr"), row.names = c("oranges", "apple", "lemons"), class = "data.frame")
Upvotes: 0
Views: 77
Reputation: 11480
You can solve this issue like this:
df
being your real data.frame.
df[]<-df[match(rownames(df),df$Fruits),]
Upvotes: 2