I want to aggregate a certain value in a data.frame based on a common character in R.
The Problem is that I am not interested in different directions of the pairwise combination.
So for instance
d = data.frame( x = LETTERS[1:5], y = LETTERS[5:1] )
x y
1 A E
2 B D
3 C C
4 D B
5 E A
The combination would be then calculated like this:
d$z <- paste0(d$x,d$y,sep="_")
The problem is that i am not interested in pairwise differences. So A_E
should be the same as E_A
in this simple example.
Is there a clever short solution to paste them? I am currently thinking about sorting each one before combining them into a vector.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…