

Hi,
Is there any way to find the permutation function of the sorting and to
apply the function (or its inverse) elsewhere?
For example, the following permutation function from the sorting in the
matrix form is
c(1,2,3), c(2,1,3)
> sort(c("bc","ac","dd"))
[1] "ac" "bc" "dd"
I try to find it in the permutations/permute package, but I can't find it
John
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> On May 22, 2018, at 10:06 PM, John < [hidden email]> wrote:
>
> Hi,
>
> Is there any way to find the permutation function of the sorting and to
> apply the function (or its inverse) elsewhere?
>
> For example, the following permutation function from the sorting in the
> matrix form is
> c(1,2,3), c(2,1,3)
>
>> sort(c("bc","ac","dd"))
> [1] "ac" "bc" "dd"
>
I think you are asking for the `order` function.
> I try to find it in the permutations/permute package, but I can't find it
>
> John
>
> [[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thanks, David.
I got the answer from the web.
Is there any easy way to permute a set (e.g., a set of characters) by the
permutation it returns? Thanks,
> x < c(10,7,4,3,8,2)
> sort(x, index.return=TRUE)
$x
[1] 2 3 4 7 8 10
$ix
[1] 6 4 3 2 5 1
20180523 10:49 GMT+08:00 David Winsemius < [hidden email]>:
>
>
> > On May 22, 2018, at 10:06 PM, John < [hidden email]> wrote:
> >
> > Hi,
> >
> > Is there any way to find the permutation function of the sorting and to
> > apply the function (or its inverse) elsewhere?
> >
> > For example, the following permutation function from the sorting in the
> > matrix form is
> > c(1,2,3), c(2,1,3)
> >
> >> sort(c("bc","ac","dd"))
> > [1] "ac" "bc" "dd"
> >
>
> I think you are asking for the `order` function.
>
> > I try to find it in the permutations/permute package, but I can't find
> it
> >
> > John
> >
> > [[alternative HTML version deleted]]
>
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> On May 22, 2018, at 10:57 PM, John < [hidden email]> wrote:
>
> Thanks, David.
> I got the answer from the web.
> Is there any easy way to permute a set (e.g., a set of characters) by the permutation it returns? Thanks,
>
>
> > x < c(10,7,4,3,8,2)
> > sort(x, index.return=TRUE)
> $x
> [1] 2 3 4 7 8 10
>
> $ix
> [1] 6 4 3 2 5 1
>
I don't understand what is being requested. The $ix value is the same as the one returned `by order`.
David.
> 20180523 10:49 GMT+08:00 David Winsemius < [hidden email]>:
>
>
> > On May 22, 2018, at 10:06 PM, John < [hidden email]> wrote:
> >
> > Hi,
> >
> > Is there any way to find the permutation function of the sorting and to
> > apply the function (or its inverse) elsewhere?
> >
> > For example, the following permutation function from the sorting in the
> > matrix form is
> > c(1,2,3), c(2,1,3)
> >
> >> sort(c("bc","ac","dd"))
> > [1] "ac" "bc" "dd"
> >
>
> I think you are asking for the `order` function.
>
> > I try to find it in the permutations/permute package, but I can't find it
> >
> > John
> >
> > [[alternative HTML version deleted]]
>
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Perhaps the question was "what is indexing"?
On May 23, 2018 5:06:39 AM GMT+02:00, David Winsemius < [hidden email]> wrote:
>
>
>> On May 22, 2018, at 10:57 PM, John < [hidden email]> wrote:
>>
>> Thanks, David.
>> I got the answer from the web.
>> Is there any easy way to permute a set (e.g., a set of characters) by
>the permutation it returns? Thanks,
>>
>>
>> > x < c(10,7,4,3,8,2)
>> > sort(x, index.return=TRUE)
>> $x
>> [1] 2 3 4 7 8 10
>>
>> $ix
>> [1] 6 4 3 2 5 1
>>
>
>I don't understand what is being requested. The $ix value is the same
>as the one returned `by order`.
>
>David.
>
>
>> 20180523 10:49 GMT+08:00 David Winsemius < [hidden email]>:
>>
>>
>> > On May 22, 2018, at 10:06 PM, John < [hidden email]> wrote:
>> >
>> > Hi,
>> >
>> > Is there any way to find the permutation function of the sorting
>and to
>> > apply the function (or its inverse) elsewhere?
>> >
>> > For example, the following permutation function from the sorting
>in the
>> > matrix form is
>> > c(1,2,3), c(2,1,3)
>> >
>> >> sort(c("bc","ac","dd"))
>> > [1] "ac" "bc" "dd"
>> >
>>
>> I think you are asking for the `order` function.
>>
>> > I try to find it in the permutations/permute package, but I can't
>find it
>> >
>> > John
>> >
>> > [[alternative HTML version deleted]]
>>
>>
>
>______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp>PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html>and provide commented, minimal, selfcontained, reproducible code.

Sent from my phone. Please excuse my brevity.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> sort(c("bc","ac","dd"), index.return=TRUE)
$x
[1] "ac" "bc" "dd"
$ix
[1] 2 1 3
We have the permutation, namely 1>2, 2>1, 3>3.
How can I apply the permutation function to a new set
c("D","E", "F")?
so that the result is
c("E","D", "F").
20180523 11:06 GMT+08:00 David Winsemius < [hidden email]>:
>
>
> > On May 22, 2018, at 10:57 PM, John < [hidden email]> wrote:
> >
> > Thanks, David.
> > I got the answer from the web.
> > Is there any easy way to permute a set (e.g., a set of characters) by
> the permutation it returns? Thanks,
> >
> >
> > > x < c(10,7,4,3,8,2)
> > > sort(x, index.return=TRUE)
> > $x
> > [1] 2 3 4 7 8 10
> >
> > $ix
> > [1] 6 4 3 2 5 1
> >
>
> I don't understand what is being requested. The $ix value is the same as
> the one returned `by order`.
>
> David.
>
>
> > 20180523 10:49 GMT+08:00 David Winsemius < [hidden email]>:
> >
> >
> > > On May 22, 2018, at 10:06 PM, John < [hidden email]> wrote:
> > >
> > > Hi,
> > >
> > > Is there any way to find the permutation function of the sorting and
> to
> > > apply the function (or its inverse) elsewhere?
> > >
> > > For example, the following permutation function from the sorting in
> the
> > > matrix form is
> > > c(1,2,3), c(2,1,3)
> > >
> > >> sort(c("bc","ac","dd"))
> > > [1] "ac" "bc" "dd"
> > >
> >
> > I think you are asking for the `order` function.
> >
> > > I try to find it in the permutations/permute package, but I can't
> find it
> > >
> > > John
> > >
> > > [[alternative HTML version deleted]]
> >
> >
>
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> On May 22, 2018, at 11:37 PM, John < [hidden email]> wrote:
>
>
> > sort(c("bc","ac","dd"), index.return=TRUE)
> $x
> [1] "ac" "bc" "dd"
>
> $ix
> [1] 2 1 3
>
>
> We have the permutation, namely 1>2, 2>1, 3>3.
> How can I apply the permutation function to a new set
> c("D","E", "F")?
> so that the result is
> c("E","D", "F").
So you want:
> x < sort(c("bc","ac","dd"), index.return=TRUE)
> x
$x
[1] "ac" "bc" "dd"
$ix
[1] 2 1 3
> c("D","E", "F")[ x$ix ]
[1] "E" "D" "F"
>
> 20180523 11:06 GMT+08:00 David Winsemius < [hidden email]>:
>
>
> > On May 22, 2018, at 10:57 PM, John < [hidden email]> wrote:
> >
> > Thanks, David.
> > I got the answer from the web.
> > Is there any easy way to permute a set (e.g., a set of characters) by the permutation it returns? Thanks,
> >
> >
> > > x < c(10,7,4,3,8,2)
> > > sort(x, index.return=TRUE)
> > $x
> > [1] 2 3 4 7 8 10
> >
> > $ix
> > [1] 6 4 3 2 5 1
> >
>
> I don't understand what is being requested. The $ix value is the same as the one returned `by order`.
>
> David.
>
>
> > 20180523 10:49 GMT+08:00 David Winsemius < [hidden email]>:
> >
> >
> > > On May 22, 2018, at 10:06 PM, John < [hidden email]> wrote:
> > >
> > > Hi,
> > >
> > > Is there any way to find the permutation function of the sorting and to
> > > apply the function (or its inverse) elsewhere?
> > >
> > > For example, the following permutation function from the sorting in the
> > > matrix form is
> > > c(1,2,3), c(2,1,3)
> > >
> > >> sort(c("bc","ac","dd"))
> > > [1] "ac" "bc" "dd"
> > >
> >
> > I think you are asking for the `order` function.
> >
> > > I try to find it in the permutations/permute package, but I can't find it
> > >
> > > John
> > >
> > > [[alternative HTML version deleted]]
> >
> >
>
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hello,
Like David said, what you are trying to do with sort() can be done with
order() in a much easier way.
First, your code
x < sort(c("bc","ac","dd"), index.return=TRUE)
Now, with function order()
i < order(c("bc", "ac", "dd"))
y < c("D","E", "F")[i]
y
#[1] "E" "D" "F"
# This will give you the inverse,
# just apply order() to the output of order(),
# function order() is its own inverse
y[ order(i) ]
#[1] "D" "E" "F"
Finally, compare the results and see that they are exactly the same.
identical(x$ix, i)
#[1] TRUE
Hope this helps,
Rui Barradas
On 5/23/2018 4:37 AM, John wrote:
>> sort(c("bc","ac","dd"), index.return=TRUE)
> $x
> [1] "ac" "bc" "dd"
>
> $ix
> [1] 2 1 3
>
>
> We have the permutation, namely 1>2, 2>1, 3>3.
> How can I apply the permutation function to a new set
> c("D","E", "F")?
> so that the result is
> c("E","D", "F").
>
>
>
>
> 20180523 11:06 GMT+08:00 David Winsemius < [hidden email]>:
>
>>
>>
>>> On May 22, 2018, at 10:57 PM, John < [hidden email]> wrote:
>>>
>>> Thanks, David.
>>> I got the answer from the web.
>>> Is there any easy way to permute a set (e.g., a set of characters) by
>> the permutation it returns? Thanks,
>>>
>>>
>>>> x < c(10,7,4,3,8,2)
>>>> sort(x, index.return=TRUE)
>>> $x
>>> [1] 2 3 4 7 8 10
>>>
>>> $ix
>>> [1] 6 4 3 2 5 1
>>>
>>
>> I don't understand what is being requested. The $ix value is the same as
>> the one returned `by order`.
>>
>> David.
>>
>>
>>> 20180523 10:49 GMT+08:00 David Winsemius < [hidden email]>:
>>>
>>>
>>>> On May 22, 2018, at 10:06 PM, John < [hidden email]> wrote:
>>>>
>>>> Hi,
>>>>
>>>> Is there any way to find the permutation function of the sorting and
>> to
>>>> apply the function (or its inverse) elsewhere?
>>>>
>>>> For example, the following permutation function from the sorting in
>> the
>>>> matrix form is
>>>> c(1,2,3), c(2,1,3)
>>>>
>>>>> sort(c("bc","ac","dd"))
>>>> [1] "ac" "bc" "dd"
>>>>
>>>
>>> I think you are asking for the `order` function.
>>>
>>>> I try to find it in the permutations/permute package, but I can't
>> find it
>>>>
>>>> John
>>>>
>>>> [[alternative HTML version deleted]]
>>>
>>>
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thanks, David, Rui and Jeff!!! The function order works much better.
I should have used an example where the permutation and its inverse are not
identical:
> i < order(c("B", "C", "A"))
> i
[1] 3 1 2
> c("D","E", "F")[i]
[1] "F" "D" "E"
> c("D","E", "F")[order(i)]
[1] "E" "F" "D"
20180523 14:18 GMT+08:00 Rui Barradas < [hidden email]>:
> Hello,
>
> Like David said, what you are trying to do with sort() can be done with
> order() in a much easier way.
>
> First, your code
>
> x < sort(c("bc","ac","dd"), index.return=TRUE)
>
>
> Now, with function order()
>
>
> i < order(c("bc", "ac", "dd"))
>
> y < c("D","E", "F")[i]
> y
> #[1] "E" "D" "F"
>
> # This will give you the inverse,
> # just apply order() to the output of order(),
> # function order() is its own inverse
>
> y[ order(i) ]
> #[1] "D" "E" "F"
>
>
> Finally, compare the results and see that they are exactly the same.
>
> identical(x$ix, i)
> #[1] TRUE
>
>
> Hope this helps,
>
> Rui Barradas
>
> On 5/23/2018 4:37 AM, John wrote:
>
>> sort(c("bc","ac","dd"), index.return=TRUE)
>>>
>> $x
>> [1] "ac" "bc" "dd"
>>
>> $ix
>> [1] 2 1 3
>>
>>
>> We have the permutation, namely 1>2, 2>1, 3>3.
>> How can I apply the permutation function to a new set
>> c("D","E", "F")?
>> so that the result is
>> c("E","D", "F").
>>
>>
>>
>>
>> 20180523 11:06 GMT+08:00 David Winsemius < [hidden email]>:
>>
>>
>>>
>>> On May 22, 2018, at 10:57 PM, John < [hidden email]> wrote:
>>>>
>>>> Thanks, David.
>>>> I got the answer from the web.
>>>> Is there any easy way to permute a set (e.g., a set of characters) by
>>>>
>>> the permutation it returns? Thanks,
>>>
>>>>
>>>>
>>>> x < c(10,7,4,3,8,2)
>>>>> sort(x, index.return=TRUE)
>>>>>
>>>> $x
>>>> [1] 2 3 4 7 8 10
>>>>
>>>> $ix
>>>> [1] 6 4 3 2 5 1
>>>>
>>>>
>>> I don't understand what is being requested. The $ix value is the same as
>>> the one returned `by order`.
>>>
>>> David.
>>>
>>>
>>> 20180523 10:49 GMT+08:00 David Winsemius < [hidden email]>:
>>>>
>>>>
>>>> On May 22, 2018, at 10:06 PM, John < [hidden email]> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> Is there any way to find the permutation function of the sorting and
>>>>>
>>>> to
>>>
>>>> apply the function (or its inverse) elsewhere?
>>>>>
>>>>> For example, the following permutation function from the sorting in
>>>>>
>>>> the
>>>
>>>> matrix form is
>>>>> c(1,2,3), c(2,1,3)
>>>>>
>>>>> sort(c("bc","ac","dd"))
>>>>>>
>>>>> [1] "ac" "bc" "dd"
>>>>>
>>>>>
>>>> I think you are asking for the `order` function.
>>>>
>>>> I try to find it in the permutations/permute package, but I can't
>>>>>
>>>> find it
>>>
>>>>
>>>>> John
>>>>>
>>>>> [[alternative HTML version deleted]]
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide http://www.Rproject.org/posti>> ngguide.html
>> and provide commented, minimal, selfcontained, reproducible code.
>>
>>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

