我想引用下面的两个数据框x和y,提供获取元素以提供给下面的函数的范围,首先x取所有y元素,依此类推,以获得z的索引结果,如同格式如z [1:3] ...我知道我可以在lapply函数中使用expand.grid来轻松引用它们并滚动整行长度。但是这个方法不适合这个例子,因为我想保持z的列表结构作为输出。
# I have a list of elements and its sequences:
z <- list ( c( 9,8,7,6,5,4,3,2,1,0 ), c( 5,4,3,2,1,0,1,2,3,4 ) )
x <- c( 1,2 )
y <- c( 1,2,3,4,5,6,7,8,9,10 )
Sx <- seq(x)
Sy <- seq(y)
# were sequential data frames are made as to attempt to index them
sequentially to z:
addbeg <- 0
addend <- length ( x )
C <- c( addbeg , seq ( addend ) )
newpairs0 <- cbind ( C[-length(C)] , C[-1] )
addbeg <- 0
addend <- length( y )
D <- c( addbeg , seq(addend ) )
newpairs1 <- cbind ( D[-length(D)] , D[-1] )
# Though doing this via a mapply function where to index the two prior results but can not figure it out.
# The desired output from a unespecied function is:
[[1]]
[1] 9 8 7 6 5 4 3 2 1 0
[[2]]
[1] 5 4 3 2 1 0 1 2 3 4