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 1 year has passed since last update.

allcombinations() --- R の expand.grid()

Posted at

与えられた引数の値のすべての組み合わせから DataFrame を作る。
R の expand.grid() に相当するもの。

DataFrames の中に,allcombinations() がある。
DataFrames が v1.5.0 以上でないと存在しない。

allcombinations(DataFrame; kwargs...)
allcombinations(DataFrame, pairs::Pair...)

第1引数は DataFrame
第2引数以降は kwargs... すなわち,列名 = ベクトル または pairs::Pair... すなわち "列名"=> ベクトルの指定(いずれか一方に統一すること)を繰り返す。

使用例 kwargs... を使う

using DataFrames

df = allcombinations(DataFrame,
    letters = [:a, :b, :c], numbers = [1,2,3], other = ["male", "female"])
18×3 DataFrame
Row letters numbers other
Symbol Int64 String
1 a 1 male
2 b 1 male
3 c 1 male
4 a 2 male
5 b 2 male
6 c 2 male
7 a 3 male
8 b 3 male
9 c 3 male
10 a 1 female
11 b 1 female
12 c 1 female
13 a 2 female
14 b 2 female
15 c 2 female
16 a 3 female
17 b 3 female
18 c 3 female

使用例 pairs::Pair... を使う

同じことを別の指定法で

df = allcombinations(DataFrame,
    "letters" => [:a, :b, :c], "numbers" => [1,2,3], "other" => ["male", "female"])
18×3 DataFrame
Row letters numbers other
Symbol Int64 String
1 a 1 male
2 b 1 male
3 c 1 male
4 a 2 male
5 b 2 male
6 c 2 male
7 a 3 male
8 b 3 male
9 c 3 male
10 a 1 female
11 b 1 female
12 c 1 female
13 a 2 female
14 b 2 female
15 c 2 female
16 a 3 female
17 b 3 female
18 c 3 female
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?