IP-Address
Here is yet another way: library(gtools) DF[mixedorder(DF$ip), ]
On Fri, May 29, 2009 at 12:51 AM, edwin Sendjaja <edwin_0712 at msn.com> wrote:
Hi,
Is there any way to sort a tabel with a colum with IP-address?
table:
id rank color status ip
138 29746 yellow no 162.131.58.26
138 29746 red ?yes ?162.131.58.16
138 29746 blue yes ?162.131.58.10
138 29746 red no ?162.131.58.17
138 29746 yellow no 162.131.58.14
138 29746 red no ?162.131.58.13
138 29746 yellow ?no 162.132.58.15
139 29746 green no ?162.252.20.69
140 29746 red yes ?162.254.20.71
141 29746 yellow no ?163.253.7.153
142 31804 green yes ?163.253.20.114
144 32360 black yes ?161.138.45.226
....
Unfortunately, order doesn't work as I want.
I found an half solusion from John:
mysort <- function(x){
?sort.helper <- function(x){
? ?prefix <- strsplit(x, "[0-9]")
? ?prefix <- sapply(prefix, "[", 1)
? ?prefix[is.na(prefix)] <- ""
? ?suffix <- strsplit(x, "[^0-9]")
? ?suffix <- as.numeric(sapply(suffix, "[", 2))
? ?suffix[is.na(suffix)] <- -Inf
? ?remainder <- sub("[^0-9]+", "", x)
? ?remainder <- sub("[0-9]+", "", remainder)
? ?if (all (remainder == "")) list(prefix, suffix)
? ?else c(list(prefix, suffix), Recall(remainder))
? ?}
?ord <- do.call("order", sort.helper(x))
?x[ord]
? }
mysort (data$ip) ?captured only the ip-adresse. How can I capture the whole table and sorted?(ID rank color status ip)
Thank you in advance.
eddie
_________________________________________________________________ ? ? ? ?[[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.