0
0

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 3 years have passed since last update.

pivot longer, pivot widerのひな型(gather spreadの上位互換)

Posted at

この記事ではR version 3.6.3、tidyverseパッケージを使っています。

コード

library(tidyverse)
iris %>% 
  pivot_longer(
    cols = c( ###列の選択
      "Sepal.Length", 
      "Sepal.Width",
      "Petal.Length",
      "Petal.Width"
      ),
    names_to = "traits", #列名を格納する列の名前
    values_to = "value" #値を格納する列の名前
  )

結果

Species traits value
setosa Sepal.Length 5.1
setosa Sepal.Width 3.5
setosa Petal.Length 1.4
setosa Petal.Width 0.2
setosa Sepal.Length 4.9
setosa Sepal.Width 3.0
setosa Petal.Length 1.4

補足

かなりいろいろできそう。今後も更新予定

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?