赞
踩
例如:
lst <- vector("list",3) #vector("list",length)是创建一个含有length个元素的列表
a <- matrix(data = c(5,8,6,8,9,12,1,2,3,4,5,6,13,0,5,7,21,4),nrow = 3)
j <- 1
for(i in 1:3)
{
lst[[i]] <- a[,j:(j+1)]
j <- j + 2
}
> a
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 5 8 1 4 13 7
[2,] 8 9 2 5 0 21
[3,] 6 12 3 6 5 4
> lst[[1]]
[,1] [,2]
[1,] 5 8
[2,] 8 9
[3,] 6 12
> lst[[2]]
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
> lst[[3]]
[,1] [,2]
[1,] 13 7
[2,] 0 21
[3,] 5 4
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。