r - 如何将属于一组的元素排列在一行中
问题描述
我的数据是这样的-
p1 x1
p2 x2
p1 x3
p7 x4
p5 x5
p2 x6
p5 x7
p7 x8
p1 x9
p2 x10
我想这样安排——
p1 x1,x2,x9
p2 x2,x6,x10
p7 x4,x8
p5 x5,x7
如何使用 R/命令行或 Excel 执行此操作?
解决方案
我们可以用aggregate
aggregate(col2 ~ col1, df1, toString)
如果有重复的元素,获取unique
行并执行aggregate
aggregate(col2 ~ col1, unique(df1), toString)
推荐阅读
- database - 我的基本混淆功能正确吗?(用于隐藏数据库中的数据)
- batch-file - 有没有一种简单的方法可以在使用选项时将变量 %errorlevel% 更改为另一个变量?
- typescript - 在编译时获取泛型的名称
- mysql - 无效使用组功能
- c - 如何在链接时声明变量并将其地址注册到数组中
- javascript - javascript - ionRangeSlider 动态值
- c# - 从服务工作者程序中的 appsettings.js 获取连接字符串
- jquery - 使用类在 jQuery 表中显示/隐藏行
- html - Python3 UnicodeEncodeError 与熊猫同时读取 CSV
- linux - 想要按天计算总尝试次数