Dear all, I am using expand.grid for calculating all the possible values between four pairs. I would like to ask you if it is possible to filter the result out, so to keep all unique pairs. In my algorithm the input c(1,2) produces the same results as the c(2,1) so for example in the following code below> expand.grid(c(1,2,3),c(1,2,3))Var1 Var2 1 1 1 2 2 1 3 3 1 4 1 2 5 2 2 6 3 2 7 1 3 8 2 3 9 3 3 2,1 duplicates with 1,2 3,1 duplicates with 1,3 How I can removed these entries? The expand.grid function does not seem to have more arguments. Regards Alex [[alternative HTML version deleted]]
Something like this? x <- expand.grid(c(1,2,3),c(1,2,3)) x[x[,2]>=x[,1],] Var1 Var2 1 1 1 4 1 2 5 2 2 7 1 3 8 2 3 9 3 3 Regards S?ren -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alaios Sent: 24. marts 2012 16:09 To: R help Subject: [R] expand.grid (the half!) Dear all, I am using expand.grid for calculating all the possible values between four pairs. I would like to ask you if it is possible to filter the result out, so to keep all unique pairs. In my algorithm the input c(1,2) produces the same results as the c(2,1) so for example in the following code below> expand.grid(c(1,2,3),c(1,2,3))? Var1 Var2 1??? 1??? 1 2??? 2??? 1 3??? 3??? 1 4??? 1??? 2 5??? 2??? 2 6??? 3??? 2 7??? 1??? 3 8??? 2??? 3 9??? 3??? 3 2,1 duplicates with 1,2 3,1 duplicates with 1,3 How I can removed these entries? The expand.grid function does not seem to have more arguments. Regards Alex [[alternative HTML version deleted]]
On 24-03-2012, at 16:08, Alaios wrote:> Dear all, > I am using expand.grid for calculating all the possible values between four pairs. > > I would like to ask you if it is possible to filter the result out, so to keep all unique pairs. In my algorithm the input c(1,2) produces the same results as the c(2,1) > > so for example in the following code below > >> expand.grid(c(1,2,3),c(1,2,3)) > Var1 Var2 > 1 1 1 > 2 2 1 > 3 3 1 > 4 1 2 > 5 2 2 > 6 3 2 > 7 1 3 > 8 2 3 > 9 3 3 > > > 2,1 duplicates with 1,2 > 3,1 duplicates with 1,3 > > How I can removed these entries? The expand.grid function does not seem to have more arguments.http://r.789695.n4.nabble.com/unique-combinations-td4220850.html http://stackoverflow.com/questions/9028369/removing-duplicate-combinations-in-r-irrespective-of-order Berend