Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data.frame row by ID

Tags:

r

I have a data.frame $X$ obtained from a data.frame $Y$ by filtering out some rows. I am now interested in accessing a row with ID $i$ (By ID I mean the value appearing in the very first column, generated by R). I am only aware of the $X[i,]$ command, which, as far as I understand, gives me the $i$-th row in $X$ but not the row with ID $i$.

Is there any other command to access a row by its id?

like image 918
user695652 Avatar asked Sep 01 '25 10:09

user695652


1 Answers

As an alternative, you can use quotes "" to refer to a given row by its respective element of rownames(),e.g.:

X["35",]
like image 95
Maxim.K Avatar answered Sep 02 '25 23:09

Maxim.K