Sunday, 8 September 2013

Find 5 rows with the largest column values

Find 5 rows with the largest column values

I have a very large data file, and my goal is to find 5 rows that have the
5 largest values in the V4 column, so I sorted the data, and got the
largest values, and then using a logical expression tried to find the
entire rows. The problem is that even though I can find the top 5 values,
the logical expression only gives me 3 rows instead of 5.
> h<-head(sort.int(d$V4, decreasing=T), 5)
> h
[1] 65506 39681 32306 29028 27535
> d[d$V4==h,]
V1 V2 V3 V4 V5
373135 1504839 1990 1 27535 77963;4;21;3;49;64;13;113;7;6
1365437 2141627 2010 1 39681 8;258;236;39;86;28;58
1797593 1822695 1992 1 32306 0
So, why I cannot find the corresponding rows for 65506, and 29028? Is
there any other way to solve this problem?
Thanks

No comments:

Post a Comment