5

I have a data frame like this:

       x1    x2    x3
271    3     5      2
553    2     4      1
563    2     5      3

When I try to select a row based on the row name, e.g. 271, it errors:

df[271, ]
# Error in xj[i, , drop = FALSE] : subscript out of bounds

How can I select these rows based on the row names (e.g. 271, 553, 563)?

1
  • 3
    Row name in apostrophes: DFsubset['271',] Commented May 14, 2014 at 10:59

1 Answer 1

13

You need to reference the rownames of your data.frame:

dfsub[rownames(dfsub) == 271,] #where dfsub is your subsetted data.frame

EDIT:

as @koekenbakker commented, there is a shorthand to reference the rownames by using ''. So this would be:

dfsub['271',] #where dfsub is your subsetted data.frame and 271 the rowname
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.