To: r-help-request at lists.R-project.org From: "Dr. Chris Wills" <cwills at ucsd.edu> Subject: Questions about sorting and functions Cc: Bcc: X-Attachments: Dear Gang - Two questions for you: 1) I cannot figure out how to sort one column in an array, and drag the rest of the values that occupy the other columns along with the sorted values in the first column. What I would like to end up with is an array that is the same size and dimensions as the first array. When I try various configurations of sort, I keep getting vectors instead of the array I started with, and I have not found a way to make sort "bind" other values to the sorted values. 2) I used a PC version of R over the summer, and was able to use rowSum, colSum and similar functions. These (and other things) do not seem to be enabled on the Mac OS9 version. Are they enabled on the OS10 version? If not, how can I enable them? And how do I download the OS10 version? My computer does not recognize the .gz files on the website http://cran.r-project.org/bin/macosx/atlas/. Many thanks, Chris Wills -- Christopher Wills Professor of Biology Division of Biological Sciences University of California, San Diego La Jolla CA 92093 Phone 858-534-4113 Fax 858-534-7108 e-mail cwills at ucsd.edu -- Christopher Wills Professor of Biology Division of Biological Sciences University of California, San Diego La Jolla CA 92093 Phone 858-534-4113 Fax 858-534-7108 e-mail cwills at ucsd.edu -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20020918/83cfa8f2/attachment.html
At 15:14 18/09/02 -0700, you wrote:>To: r-help-request at lists.R-project.org > >From: "Dr. Chris Wills" <cwills at ucsd.edu> > >Subject: Questions about sorting and functions >Cc: > >Bcc: > >X-Attachments: >Dear Gang - > Two questions for you: > 1) I cannot figure out how to sort one column in an array, and > drag the rest of the values that occupy the other columns along with the > sorted values in the first column. What I would like to end up with is > an array that is the same size and dimensions as the first array. When I > try various configurations of sort, I keep getting vectors instead of the > array I started with, and I have not found a way to make sort "bind" > other values to the sorted values.does B<-A[,c(order(A[,2]))] do what you want? A <- rnorm(30) dim(A) <- c(5,6) A [,1] [,2] [,3] [,4] [,5] [,6] [1,] -0.1916292 -2.10928866 -0.6838013 0.9762713 -0.14361845 0.8096648 [2,] -1.5046755 0.45943149 -0.6618188 -0.6555499 -0.51070702 0.9314748 [3,] 0.4615919 2.65414221 0.2993706 0.7574201 0.13423111 0.9506057 [4,] -0.2145235 0.07009774 0.4364953 0.8839637 0.08211918 -0.1553977 [5,] 0.2170495 1.59428139 -0.5239767 0.3468852 0.31420369 -0.8838015 B <- A[c(order(A[,2])),] B [,1] [,2] [,3] [,4] [,5] [,6] [1,] -0.1916292 -2.10928866 -0.6838013 0.9762713 -0.14361845 0.8096648 [2,] -0.2145235 0.07009774 0.4364953 0.8839637 0.08211918 -0.1553977 [3,] -1.5046755 0.45943149 -0.6618188 -0.6555499 -0.51070702 0.9314748 [4,] 0.2170495 1.59428139 -0.5239767 0.3468852 0.31420369 -0.8838015 [5,] 0.4615919 2.65414221 0.2993706 0.7574201 0.13423111 0.9506057 Richard Rowe Senior Lecturer Department of Zoology and Tropical Ecology, James Cook University Townsville, Queensland 4811, Australia fax (61)7 47 25 1570 phone (61)7 47 81 4851 e-mail: Richard.Rowe at jcu.edu.au http://www.jcu.edu.au/school/tbiol/zoology/homepage.html -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
At 09:46 19/09/02 +1000, you wrote:>At 15:14 18/09/02 -0700, you wrote: >>To: r-help-request at lists.R-project.org >> >>From: "Dr. Chris Wills" <cwills at ucsd.edu> >> >>Subject: Questions about sorting and functions >>Cc: >> >>Bcc: >> >>X-Attachments: >>Dear Gang - >> Two questions for you: >> 1) I cannot figure out how to sort one column in an array, and >> drag the rest of the values that occupy the other columns along with the >> sorted values in the first column. What I would like to end up with is >> an array that is the same size and dimensions as the first array. When >> I try various configurations of sort, I keep getting vectors instead of >> the array I started with, and I have not found a way to make sort "bind" >> other values to the sorted values. > >does >B<-A[,c(order(A[,2]))]B<-A[,c(order(A[,2]))] ERROR should have been B <- A[c(order(A[,2])),] as it was in the example (2 can be any column index) Richard Rowe Senior Lecturer Department of Zoology and Tropical Ecology, James Cook University Townsville, Queensland 4811, Australia fax (61)7 47 25 1570 phone (61)7 47 81 4851 e-mail: Richard.Rowe at jcu.edu.au http://www.jcu.edu.au/school/tbiol/zoology/homepage.html -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._