标签: python sql r sorting
我有一些长度为1000且值仅为1,2的向量/列。
1000
1,2
如何对此向量/列进行排序以获得如下结果:
1 2 1 2 1 2 etc.
答案 0 :(得分:1)
在r:
一些样本数据:
x <- sample(1:2, 1000, replace = TRUE)
做的:
x[match(rep(1:2, 500), x)]
答案 1 :(得分:0)
更快:
rep(c(1,2), length=10) # [1] 1 2 1 2 1 2 1 2 1 2
对于python,请阅读this SO post。