首页 > 解决方案 > 从列表向量中消除元素

问题描述

我会从这个数据结构中删除长度为 !=4 的元素

    library(partitions)
        permListParts <- function (x) 
        {
            f <- function(pp) {
                out <- split(seq_along(pp), pp)
                myPerms <- perms(length(out))
                apply(myPerms, 2, function(x) {
                    temp <- out[x]
                    class(temp) <- c(class(temp), "equivalence")
                    temp
                })
            }
            apply(setparts(x), 2, f)
        } 
  x=c(33,45,77,23,15)     
 parts <- permListParts(length(x))
            out <- rapply(parts, function(ii) x[ii], how="replace")  

删除我使用这个代码:

for(i in 1:length(out)){
if(length(out[[i]][[1]])!=4){out=out[-i]}}

但循环不会删除我想要的元素

标签: rlistvector

解决方案


推荐阅读