我一方面有一个字符元素F的载体。
另一方面,一组函数在GF中生成两个子列表的分段版本。输出SA生成包含所需段的列表,但SA的索引具有以下格式。
[[1]]
[[1]]$`1`
[[1]]$`2`
[[2]]
[[2]]$`1`....
F <-c("a","b","c","d","e","f","g","h","i","a","b","c","d","e","f","g","h","i","j","k","l")
GF <- list(c(1,2,3,4,5,6,7,8,9) , c(2,3,4,5,6,3,2,1,3,4,5,2))
RET <- seq(length ( GF )) # SEQUENCE : NUMBER OF SUB-LISTS
LS <- c( 3 , 2 ) # LENGTH OF EACH ADDITIONAL SUB-SUB SEGMENT WITHIN TWO LISTS
fun <- function (x) split ( GF[[x]] , ceiling (seq_along (GF[[x]])/LS[[x]]))
SA <- (lapply ( RET , fun )) # OUTPUT
relist(unlist( F ), SA )
我想使用SA的scheleton来重新连接F,但是在输出SA中获取的索引格式是[[和S并且希望它全部[[。
答案 0 :(得分:1)
是的,你可以在分割功能中使用unname
F <-c("a","b","c","d","e","f","g","h","i","a","b","c","d","e","f","g","h","i","j","k","l")
GF <- list(c(1,2,3,4,5,6,7,8,9) , c(2,3,4,5,6,3,2,1,3,4,5,2))
RET <- seq(length ( GF )) # SEQUENCE : NUMBER OF SUB-LISTS
LS <- c( 3 , 2 ) # LENGTH OF EACH ADDITIONAL SUB-SUB SEGMENT WITHIN TWO LISTS
fun <- function (x) unname(split ( GF[[x]] , ceiling (seq_along (GF[[x]])/LS[[x]])))
SA <- (lapply ( RET , fun )) # OUTPUT
relist(unlist( F ), SA )