有没有一种方法可以根据过滤器来打乱 Dataframe 的行?例如,我有这样一个 Dataframe :
data=data.frame(id=c(3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26),
name=c("restructuring","restructuring","restructuring","restructuring",
"control","control","control","control","clitic filler","clitic filler","clitic filler","clitic filler","clitic filler","clitic filler","clitic filler","clitic filler","action filler","action filler","action filler","action filler","action filler","action filler","action filler","action filler")
)
其中数字3到6是“重构”,7-10是“控制”,11-18是“cltic填充器”,19-26是“操作填充器”,我希望name
列在2个连续行中不具有相同的值。
我试过:shuffled_data= data[sample(1:nrow(data)), ]
但这显然是随机的,没有标准
2条答案
按热度按时间wrrgggsh1#
如果您的数据大约是这个大小,我会做一堆随机 Shuffle ,并找到一个(s)符合您的标准:
3j86kqsm2#
将this answer中的函数用于
min.dist = 1
: