Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python类Zip结构中用于排序的R函数_R - Fatal编程技术网

Python类Zip结构中用于排序的R函数

Python类Zip结构中用于排序的R函数,r,R,我有一个向量: dput(pos) c(2000L, 2020L, 2020L, 2040L, 2060L, 2080L, 2100L, 2120L, 2140L, 2160L, 2180L, 2200L, 2220L, 2240L, 2260L, 2280L, 2300L, 2320L, 2340L, 2360L, 2380L, 2400L, 2420L, 2440L, 2460L, 2480L, 2500L, 2520L, 2540L, 2560L, 2580L, 2600L, 26

我有一个向量:

dput(pos)

c(2000L, 2020L, 2020L, 2040L, 2060L, 2080L, 2100L, 2120L, 2140L, 2160L, 2180L, 
2200L, 2220L, 2240L, 2260L, 2280L, 2300L, 2320L, 2340L, 2360L,  2380L,
2400L, 2420L, 2440L, 2460L, 2480L, 2500L, 2520L, 2540L,  2560L, 2580L,
2600L, 2620L, 2640L, 2660L, 2680L, 2700L, 2720L,  2740L, 2760L, 2780L,
2800L, 2820L, 2840L, 2860L, 2880L, 2900L,  2920L, 2940L, 2960L, 2980L)
我想对
pos
进行排序,以便得到以下向量:

2000、2980、2020、2960、2040、2940等

我写了一个函数:

for (i in seq_along(pos)){  
el1 <- min(range(pos))   
el2 <- max(range(pos))   
res <- rbind(el1, el2)  
pos <- pos[!pos == c(el1, el2)]}
for(i在seq_中沿(pos)){

el1您可以反转向量并与原始向量结合,根据偶数/奇数序列选择一个或另一个:

  newdata <- data.frame(cbind(dat=data, rev=c(1, rev(data)[- length(data)]), n=seq(1:length(data)))) %>%
  mutate(res=ifelse(n%%2==1, dat, rev)) %>%
  select(res)
newdata%
变异(res=ifelse(n%%2==1,dat,rev))%>%
选择(res)

2000、2980作为排序后的
pos
的第一个值从何而来?
pos
的最小值是2020,最大值是2960。请立即检查我编辑了语法,因为
字符是不必要的,并且很难粘贴到R控制台中。现在看起来不错。我喜欢这些替代解决方案,但总是可以如何修复我的方法中缺少的内容
  newdata <- data.frame(cbind(dat=data, rev=c(1, rev(data)[- length(data)]), n=seq(1:length(data)))) %>%
  mutate(res=ifelse(n%%2==1, dat, rev)) %>%
  select(res)