Let's say I have a given dataframe df, that looks like this:
df
Group <- c("A","B","C","D","E","B","D","E")
Value <- c(2,3,2,2,1,5,4,4)
df <- data.frame(Group, Value)
df
Group Value
1 A 2
2 B 3
3 C 2
4 D 2
5 E 1
6 B 5
7 D 4
8 E 4
I want to look for duplicates in Group
and then put the two Values
that go with that Group
in seperate columns.
I also want to remove any row or Group
with only one Value
(per group).
So the resulting dataframe in this case would look like this:
new_df
Group Value1 Value2
1 B 3 5
2 D 2 4
3 E 1 4
I would be very happy, if someone could help me with this!
Thank you very much in advance!