Print one column of data frame with row names

前端 未结 2 875
野的像风
野的像风 2021-02-01 15:39

Consider a data frame with custom row names:

> data <- data.frame(a=1:3,b=2:4,c=3:5,row.names=c(\"x\",\"y\",\"z\"))
> data
  a b c
x 1 2 3
y 2 3 4
z 3 4         


        
相关标签:
2条回答
  • 2021-02-01 16:33

    You can use the drop argument (see also ?'['):

    data[,"c", drop=FALSE]
    

    gives you a data.frame

      c
    x 3
    y 4
    z 5
    
    0 讨论(0)
  • 2021-02-01 16:35

    An even easier way is data['c'], which will result in the same output:

      c
    x 3
    y 4
    z 5
    
    0 讨论(0)
提交回复
热议问题