12
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【R】dplyrで連番を追加する

Last updated at Posted at 2016-01-07

{dplyr}で連番を追加する方法。
何かもっといい方法が有るような気がする… -> 解決しました。

iris %>%
  group_by(Species) %>%
  mutate(add_one = 1, num = cumsum(add_one)) %>%
  select(-(add_one)) %>%
  print(n = 51)  # 確認のため

@hoxo_m さんよりdplyr::row_numberを教えてもらいました。
ありがとうございます!

iris %>%
  group_by(Species) %>%
  mutate(num = row_number()) %>%
  print(n = 51) # 確認のため

12
13
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?