How to get row from R data.frame

后端 未结 5 602
温柔的废话
温柔的废话 2020-12-23 16:02

I have a data.frame with column headers.

How can I get a specific row from the data.frame as a list (with the column headers as keys for the list)?

Specific

5条回答
  •  爱一瞬间的悲伤
    2020-12-23 16:14

    Try:

    > d <- data.frame(a=1:3, b=4:6, c=7:9)
    
    > d
      a b c
    1 1 4 7
    2 2 5 8
    3 3 6 9
    
    > d[1, ]
      a b c
    1 1 4 7
    
    > d[1, ]['a']
      a
    1 1
    

提交回复
热议问题