Print one column of data frame with row names

前端 未结 2 912
野的像风
野的像风 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条回答
  •  Happy的楠姐
    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
    

提交回复
热议问题