Add rep vector to dataframe with uneven total rows

前端 未结 1 1878
既然无缘
既然无缘 2021-01-27 16:42

I\'m trying to find a way of automating a large dataset to add two factors but the data may contain uneven rows.

I\'ve tried to do this with the \'rep\' function but thi

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 17:04

    rep()'s length.out argument is one option:

    df$state<-factor(rep(1:2, length.out = nrow(df)))
    

    0 讨论(0)
提交回复
热议问题