Convert a row of a data frame to vector

前端 未结 6 605
予麋鹿
予麋鹿 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:24

    Columns of data frames are already vectors, you just have to pull them out. Note that you place the column you want after the comma, not before it:

    > newV <- df[,1]
    > newV
    [1] 1 2 4 2
    

    If you actually want a row, then do what Ben said and please use words correctly in the future.

提交回复
热议问题