Convert a row of a data frame to vector

前端 未结 6 606
予麋鹿
予麋鹿 2020-12-04 09:05

I want to create a vector out of a row of a data frame. But I don\'t want to have to row and column names. I tried several things... but had no luck.

This is my data

6条回答
  •  伪装坚强ぢ
    2020-12-04 09:27

    I recommend unlist, which keeps the names.

    unlist(df[1,])
      a   b   c 
    1.0 2.0 2.6 
    
    is.vector(unlist(df[1,]))
    [1] TRUE
    

    If you don't want a named vector:

    unname(unlist(df[1,]))
    [1] 1.0 2.0 2.6
    

提交回复
热议问题