Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 如何连续地从列表中提取数据_R_List - Fatal编程技术网

R 如何连续地从列表中提取数据

R 如何连续地从列表中提取数据,r,list,R,List,我有一个这样的矩阵 df1 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01)) df2 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01)) df3 <- sample(seq(1,10), size=1

我有一个这样的矩阵

df1 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df2 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df3 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df4 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df5 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df6 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df7 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df8 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df9 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df10 <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
df <- rbind(df1,df2,df3,df4,df5,df6,df7,df8,df9,df10)
dft <- sample(seq(1,10), size=100, replace=TRUE, prob=c(.02,.01,.01,.01,.01,.01,.005,.005,.01,.01))
t<- sapply(1:nrow(df), function(i) ks.test(as.vector(df[i,]), as.vector(dft)))
我可以看出我的名单很长

length(t)
[1] 377930
我想提取每两个数据,并在一个数据帧中忽略其余数据

我确实喜欢这个

c(t[[1]],t[[2]])
c(t[[6]],t[[7]])
c(t[[11]],t[[12]])
c(t[[21]],t[[22]])
c(t[[26]],t[[27]])
c(t[[31]],t[[32]])
c(t[[36]],t[[37]])
有没有更好的方法从上面的列表中提取数据

我也试着用下面的方法来做,但没有成功

result<- data.frame(matrix(NA, nrow = length(t), ncol = 1))
m <- seq(1,length(t),by=5)
for (i in seq_along(m)){
  result[[i]] = c(t[[i]]) 
  if ( i*2 > length(t) ){
    break
  }
}

resultt
的结构是一个具有固定长度的重复模式,如果我们将其转换为矩阵,我们可以更轻松地处理它:

t_matrix <- matrix(t, ncol=5, byrow=T)

t_matrix
      [,1] [,2]      [,3]        [,4]                                 [,5]                                   
 [1,] 0.11 0.5806178 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [2,] 0.08 0.9062064 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [3,] 0.11 0.5806178 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [4,] 0.08 0.9062064 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [5,] 0.04 0.9999982 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [6,] 0.05 0.9996333 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [7,] 0.15 0.2105516 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [8,] 0.08 0.9062064 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [9,] 0.08 0.9062064 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
[10,] 0.1  0.6993742 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"

@Joseph Wood请看我的问题,我为您提供了列表,我可能在您更新测试数据之前回答了。现在删除它。希望您能找到解决方案。@humans\u 008不用担心,非常感谢您的评论
t_matrix <- matrix(t, ncol=5, byrow=T)

t_matrix
      [,1] [,2]      [,3]        [,4]                                 [,5]                                   
 [1,] 0.11 0.5806178 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [2,] 0.08 0.9062064 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [3,] 0.11 0.5806178 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [4,] 0.08 0.9062064 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [5,] 0.04 0.9999982 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [6,] 0.05 0.9996333 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [7,] 0.15 0.2105516 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [8,] 0.08 0.9062064 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
 [9,] 0.08 0.9062064 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
[10,] 0.1  0.6993742 "two-sided" "Two-sample Kolmogorov-Smirnov test" "as.vector(df[i, ]) and as.vector(dft)"
t_matrix[,c(1,2)]
      [,1] [,2]     
 [1,] 0.11 0.5806178
 [2,] 0.08 0.9062064
 [3,] 0.11 0.5806178
 [4,] 0.08 0.9062064
 [5,] 0.04 0.9999982
 [6,] 0.05 0.9996333
 [7,] 0.15 0.2105516
 [8,] 0.08 0.9062064
 [9,] 0.08 0.9062064
[10,] 0.1  0.6993742