Find row name in R

后端 未结 1 1920
春和景丽
春和景丽 2021-01-29 13:19

I wonder how I can extract row name from row number?

x <- data.frame( A = 1:10, B = 21:30 )
rownames( x ) <- sample( LETTERS, 10 )
> x
   A  B
J  1 21
A         


        
1条回答
  •  -上瘾入骨i
    2021-01-29 13:33

    set.seed(42)
    x <- data.frame( A = 1:10, B = 21:30 )
    rownames( x ) <- sample( LETTERS, 10 )
    x
    ##    A  B
    ## X  1 21
    ## Z  2 22
    ## G  3 23
    ## T  4 24
    ## O  5 25
    ## K  6 26
    ## V  7 27
    ## C  8 28
    ## L  9 29
    ## R 10 30
    rownames(x)[3] #third row name
    ## [1] "G"
    rownames(x)[x$B == 30]
    ## [1] "R"
    

    0 讨论(0)
提交回复
热议问题