更广泛地旋转以解决重复项
我的数据集将单个申请号与一系列不同的申请人相关联。每个申请人居住的州都列在一栏中。
我想转换我的数据集,以便:
- 申请编号列仅具有不同的值,
- 每个州都有自己的列
- 链接到申请的申请人数计入各自的州列,
例如
应用编号 | 状态 |
---|---|
600000 | AK |
600000 | AK |
600000 | AL |
600000 | AL |
600000 | AL |
600001 | AK |
600002 | MA |
600002 | MA |
600003 | AL |
<块引用> <块引用> <块引用> <块引用>
申请号 | AK | AL | MA |
---|---|---|---|
600000 | 2 | 3 | 0 |
600001 | 1 | 0 | 0 |
600002 | 0 | 0 | 2 |
600003 | 0 | 1 | 0 |
我认为它应该使用pivot_wider和计数函数,但我对R相对较新,仍然没有了解很多东西。
任何帮助或指示将不胜感激,谢谢:)
My dataset associates a single application number with a range of different applicants. The state in which each of these applicants lives is listed in a column.
I want to transform my dataset so that:
- the application number column only features distinct values,
- each state has its own column
- the number of applicants linked to the application is counted in their respective state column
e.g.
appli.number | State |
---|---|
600000 | AK |
600000 | AK |
600000 | AL |
600000 | AL |
600000 | AL |
600001 | AK |
600002 | MA |
600002 | MA |
600003 | AL |
application number | AK | AL | MA |
---|---|---|---|
600000 | 2 | 3 | 0 |
600001 | 1 | 0 | 0 |
600002 | 0 | 0 | 2 |
600003 | 0 | 1 | 0 |
I thought it should use pivot_wider and count functions but I am relatively new to R and still haven't yet got my head around lots of stuff.
Any help or pointers would be greatly appreciated thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
或者如果你想使用
pivot_wider()
How about this:
or if you want to use
pivot_wider()