[R] Complex sort problem

David Winsemius dwinsemius at comcast.net
Thu May 17 14:35:00 CEST 2012


On May 17, 2012, at 6:45 AM, Axel Urbiz wrote:

> Dear List,
>
> Is there a way I can sort a sample based on a sort index constructed  
> from
> the data from which the sample is taken? Basically, I need to take  
> 'many'
> samples from the same source data and sort them. This can be very time
> consuming for long vectors. Is there any way I can sort the data  
> only once
> initially, and use that sort order for the samples?
>
> I believe that idea is what is implemented in tree-based  
> classifiers, so
> the data is sorted only once initially and that sort order is used  
> for the
> child nodes.
>
>
> set.seed(12345)
> x <- sample(0:100, 10)
> x.order <- order(x)
> x.sorted <- x[x.order]
>
> sample.ind <- sample(1:length(x), 5, replace = TRUE)  #sample 1/2  
> size with
> replacement
> x.sample <- x[sample.ind]
>
> x.sample.sorted <-   #??? (without sorting again)
>
> Thanks for any help on this.
>

If you had created a named vector or used a dataframe with rownames  
you would have a record of the original sort order.

> Regards,
> Axel.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list