RGui
RGui

Reputation: 23

R List row name

I have a (one column) list called Test in R.

When I view it in R I get something like this:

> Test
                    Value
569                 N
1012                Y
4279                N
7588                N
3434                N
2408                Y
1958                Y
1251                Y

How do I reference the "row name"? I.e. 569, 1012, 4279 etc.

I want to find for example the Value at "row" 1012 (which is "Y" here). I've tried using Test[1], Test[,1] etc. but the first column isn't really a column. I don't know what it is. Hopefully this makes some kind of sense. I don't even know what to look for to find the solution to this.

Upvotes: 2

Views: 3428

Answers (1)

Gavin Simpson
Gavin Simpson

Reputation: 174778

If Test is a data frame;

txt <- "                    Value
569                 N
1012                Y
4279                N
7588                N
3434                N
2408                Y
1958                Y
1251                Y
"
Test <- read.table(textConnection(txt), header = TRUE)

then,

> Test["1012", ]
[1] Y
Levels: N Y

will extract the required row.

Upvotes: 1

Related Questions