Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.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
如何使用R、Python或Excel拆分数据,使它们在每n行之后水平分布?_Python_R_Excel - Fatal编程技术网

如何使用R、Python或Excel拆分数据,使它们在每n行之后水平分布?

如何使用R、Python或Excel拆分数据,使它们在每n行之后水平分布?,python,r,excel,Python,R,Excel,我想根据下面的输入实现下面的输出。问题在于更大的数据集(>100k) 输入文件: AB1 AB2 AB3 AB4 AB5 AB6 AB7 AB8 AB9 AB10 输出文件:(每2行之后) AB1 AB2 AB3 AB4 AB5 AB6 AB7 AB8 AB9 AB10 我建议使用此基本R解决方案。您可以使用rep()每隔两行创建一个索引,然后使用unstack()获得所需的输出。我将您共享的数据用作df。代码如下: #Data df <- structure(list(V1 = c(&q

我想根据下面的输入实现下面的输出。问题在于更大的数据集(>100k)

输入文件: AB1 AB2 AB3 AB4 AB5 AB6 AB7 AB8 AB9 AB10 输出文件:(每2行之后) AB1 AB2 AB3 AB4 AB5 AB6 AB7 AB8 AB9 AB10

我建议使用此
基本R
解决方案。您可以使用
rep()
每隔两行创建一个索引,然后使用
unstack()
获得所需的输出。我将您共享的数据用作
df
。代码如下:

#Data
df <- structure(list(V1 = c("AB1", "AB2", "AB3", "AB4", "AB5", "AB6", 
"AB7", "AB8", "AB9", "AB10")), row.names = c(NA, -10L), class = "data.frame")

请从下一页重复和。“演示如何解决此编码问题”不是堆栈溢出问题。你必须做一个诚实的尝试,然后问一个关于你的算法或技术的具体问题。谢谢你花了这么多精力来解决这个问题。如果你知道如何求解,请至少指导我这个方向。它也是矩阵(input,ncol=2,byrow=TRUE)
Input = c("AB1", "AB2", "AB3", "AB4", "AB5", "AB6", "AB7", "AB8", "AB9", "AB10")

cbind(Input[seq(1,length(Input),2)],
    Input[seq(2,length(Input),2)])

     [,1]  [,2]  
[1,] "AB1" "AB2" 
[2,] "AB3" "AB4" 
[3,] "AB5" "AB6" 
[4,] "AB7" "AB8" 
[5,] "AB9" "AB10"
#Data
df <- structure(list(V1 = c("AB1", "AB2", "AB3", "AB4", "AB5", "AB6", 
"AB7", "AB8", "AB9", "AB10")), row.names = c(NA, -10L), class = "data.frame")
#Create an index
df$index <- paste0('V',rep(1:2,length.out=nrow(df)))
#Reshape
df2 <- unstack(df)
   V1   V2
1 AB1  AB2
2 AB3  AB4
3 AB5  AB6
4 AB7  AB8
5 AB9 AB10