[R] sorting data

John Sorkin JSorkin at grecc.umaryland.edu
Fri Oct 28 16:12:54 CEST 2011


I am not sure (I can't test at the moment) but will this work?
sort(a[,4])


John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

>>> nandan amar <nandan.amar at gmail.com> 10/28/2011 10:01 AM >>>
I want to sort my following data set according to value in 4th column

 0 1 0 27877.3044386212 15.8733019973557 2640.42407064348
 0 1 1 27470.1699006254 35.4182473588807 2303.26461260826
 0 1 2 27468.0314985496 38.4400363878507 2300.05521684593
 0 1 3 27469.1130543141 40.7540672493746 2299.32564458085
 0 1 4 27442.3152643187 52.4342875797706 2277.18286686329
 0 1 5 27440.7923082136 54.8003481512783 2274.49112409585
.....

I tried following :
first i wanted just to sort 4th column
>a<-read.tables("file_namr")
>attributes(a)

gives class as
$class
[1] "data.frame"

and

> sort(a[4])
Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing =
decreasing)) :
  undefined columns selected

How can I sort the data according to value in 4th column and print
along
with other columns
-- 

Amar Kumar Nandan
Karnataka, India, 560100
☎:+91-9019054471
✉:nandan.amar at gmail.com 
http://aknandan.co.nr 

	[[alternative HTML version deleted]]


Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}



More information about the R-help mailing list