我有以下数据框
const isEven = number => !(number % 2)
isEven(2) // true
const isOdd = number => !!(number % 2)
isEven(3) // true
现在,我想对前两列 ID name level val1 val2
+-----+-----+---+-----+---+
| 101 | foo | A | 0.1 | 5 |
+-----+-----+---+-----+---+
| 101 | foo | B | 0.2 | 9 |
+-----+-----+---+-----+---+
| 101 | bar | A | 0.5 | 3 |
+-----+-----+---+-----+---+
| 101 | bar | B | 0.3 | 6 |
+-----+-----+---+-----+---+
| 102 | foo | A | 0.5 | 7 |
+-----+-----+---+-----+---+
| 102 | bar | A | 0.6 | 9 |
+-----+-----+---+-----+---+
和ID
进行分组,并根据列name
旋转表。基本上,将为组中的每个level
值的val1
和val2
生成新的列。
最终数据框应如下所示。
level
我该怎么做?