Re: [R] Need advise in grab the line number of sorted list in R

From: Karl Ove Hufthammer <Karl.Hufthammer_at_math.uib.no>
Date: Mon, 02 Jun 2008 15:54:04 +0200

Jason Lee:

> I have a data frame which format is like below:-
>
> X     Y     Z
> 131 22.2 3.4   4.4
> 150  20.0 12.2 4.5
>
> etc...
>
> And I have sorted the data frame. However, I would like to grab one of
> these elements in the data frame. Also, i would like to number these rows
> so that when i grab a particular line let say 150, it is able to return me
> the position of the row rather than the "150". Let say in this example,
> when i grab a value of 150, it gives me 2 rather than 150.

I'm not sure I understand what you're trying to do. Could you try to explain using code example of how you 'grab' elements?

One solution could perhaps be to simple renumber the data frame. If the data frame is named 'dat', you can do it simply by

row.names(dat) = NULL

-- 
Karl Ove Hufthammer

______________________________________________
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.
Received on Mon 02 Jun 2008 - 14:13:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 02 Jun 2008 - 15:00:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive