Re: [R] ideas on sorting

From: array chip <arrayprofile_at_yahoo.com>
Date: Mon, 14 Mar 2011 12:13:57 -0700 (PDT)

That's a smart way to do this. Thanks!

John



From: Berend Hasselman <bhh_at_xs4all.nl>
To: r-help_at_r-project.org
Sent: Mon, March 14, 2011 10:49:37 AM
Subject: Re: [R] ideas on sorting

array chip wrote:
>
> Hi, I have a character vector as below:
>
> a<-c('10','3R','4','4R','5','5R','6','6R','7','8','9','7R','1','10R','11'
> ,'11R','12','12R','13','13R','14','14R','15','15R','1R','2','2R','3','8R'
> ,'9R')
>
> Is there a clever way to sort this easily to return a vector of index that
> would
> produce a vector as below:
>
> a[index]:
>
> [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
> [11] "11" "12" "13" "14" "15" "1R" "2R" "3R" "4R" "5R"
> [21] "6R" "7R" "8R" "9R" "10R" "11R" "12R" "13R" "14R" "15R"
>

Try

index <- order(as.numeric(sub('R','000',a)))

/Berend

--
View this message in context: 
http://r.789695.n4.nabble.com/ideas-on-sorting-tp3354489p3354525.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.



      
	[[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.
Received on Mon 14 Mar 2011 - 19:17:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Mar 2011 - 19:20:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive