按说明排序

时间:2015-06-19 09:50:14

标签: python sql r sorting

我有一些长度为1000且值仅为1,2的向量/列。

如何对此向量/列进行排序以获得如下结果:

1 2 1 2 1 2 etc. 

2 个答案:

答案 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