How can I find the row number of a particular row name in R? I have found functions which allow you to find a row number for a particular matrix value, but not from a row name.
Find row number from a row name in R
You can use which
which(rownames(dat) == "theName")
Ok thanks. I did this, but this is what R returned: integer(0) It should be returning a row # somewhere in the 500s. Any ideas on what I may be doing wrong? –
Hearten
@JoelleMarie the name is probably wrong, eg
which(c("a","b") == "c")
returns integer(0)
–
Geode @Hearten in my case the labels of my dataset happened to have a lot of spaces after the name, so i had to include those spaces as part of the label I wanted to find to get it working. By typing
row.names(dat)
you should see if this was also your case, provided this is still of interest for you. –
Cuevas © 2022 - 2024 — McMap. All rights reserved.