【发布时间】:2022-01-19 22:53:14
【问题描述】:
我有一个这样的数据集:
ID color1 color2 color3 shape1 shape2 size
55 red blue NA circle triangle small
67 yellow NA NA triangle NA medium
83 blue yellow NA circle NA large
78 red yellow blue square circle large
43 green NA NA square circle small
29 yellow green NA circle triangle medium
我想创建一个数据框,其中我有每个变量的频率和百分比,但我遇到了麻烦,因为在某些情况下有多个相同变量的列。
Variable Level Freq Percent
color blue 3 27.27
red 2 18.18
yellow 4 36.36
green 2 18.18
total 11 100.00
shape circle 5 50.0
triangle 3 30.0
square 2 20.0
total 10 100.0
size small 2 33.3
medium 2 33.3
large 2 33.3
total 6 100.0
我相信我需要将这些变量转换为 long,然后使用 summarise/mutate 来获取频率,但我似乎无法弄清楚。非常感谢任何帮助。
【问题讨论】:
标签: r