Dear All, Further to answers to sorting, can someone tell me how can I sort a list that contains duplicates (name) but keeping the duplicates together when sorting the values. e.g., a data frame with name (in duplicates), Mvalues(may be different for the duplicates) name M 1234 8 1234 8.3 4321 9 4321 8.1 If I sort by M, it will be 1234, 4321, 1234, 4321 but I want to keep the duplicates together, so that it will give me 1234, 1234, 4321, 4321. I also would like to set a cut-off, so that anything below a certain values will not be sorted. Any help will be appreciated. On another subject, I have downloaded and installed R1.1 for NT, it seems to run fine but when I source codes that I have written for R1.0.1 for printing labels to my data points, instead of printing name as label, it printed some number that I have no idea what it represents, it is not the row number or anything else. The code I used is plot(x,y, main="", xlab="x", ylab="y", type="n", ylim=c(-4,4), xlim=c(7,16)) points(x[d1], y[d1], pch=1,col=c(1:256)) points(x[d2], y[d2], pch=1,col=c(1:256)) up<-(abs(y)>=2) if (sum(up)!=0) { text(x[up],y[up], col="black",labels=name[up], cex=0.2, adj=1)} What is wrong? it ran fine in R1.0.1 and it is working fine in R1.1.0 but just not taking this text command right. Any suggestion will be appreciated. Best regards, Chuang Fong Kong, Ph D Head, Microarrays Peter MacCallum Cancer Institute - Research St. Andrew's Place, East Melbourne Victoria 3002, Australia Tel: 61 3 9656-1796 or 1138 Fax: 61 3 9656-1411 e-mail: c.kong at pmci.unimelb.edu.au -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000622/ad012dbc/attachment.html
Kong, Chuang Fong asks:> > Dear All, > Further to answers to sorting, can someone tell me how can I sort a list > that contains duplicates (name) but keeping the duplicates together when > sorting the values. > e.g., a data frame with name (in duplicates), Mvalues(may be different for > the duplicates) > name M > 1234 8 > 1234 8.3 > 4321 9 > 4321 8.1 > If I sort by M, it will be 1234, 4321, 1234, 4321 but I want to keep the > duplicates together, so that it will give me 1234, 1234, 4321, 4321. I also > would like to set a cut-off, so that anything below a certain values will > not be sorted. Any help will be appreciated.Doesn't this mean you really want to sort on name and on M within name? As several people have pointed out this is precisely what order() is designed to do. I take it that the cutoff is on the value of M. OK, suppose it is the value of `coff'. sort.ind <- order(name, pmax(coff, M)) # sorting index name <- name[sort.ind] M <- M[sort.ind] Notice how using pmax() for "parallel maximum" you can implement the cutoff by raising all values below the mark up to the mark thus putting them all into the same bin as far as sorting is concerned. If your two variables are in a data frame you can combine the last two steps into one, of course. sort.ind <- order(dat$name, pmax(coff, dat$M)) dat <- dat[sort.ind, ] In fact it's not long before you are doing it all in one step: dat <- dat[order(dat$name, pmax(coff, dat$M)), ] -- Bill Venables, Statistician, CMIS Environmetrics Project CSIRO Marine Labs, PO Box 120, Cleveland, Qld, AUSTRALIA. 4163 Tel: +61 7 3826 7251 Email: Bill.Venables at cmis.csiro.au Fax: +61 7 3826 7304 http://www.cmis.csiro.au/bill.venables/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._