r - 从列表向量中消除元素
问题描述
我会从这个数据结构中删除长度为 !=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]}}
但循环不会删除我想要的元素
解决方案
推荐阅读
- c# - 如何在 C# 中的 .where 中包含子查询?
- java - 正则表达式用于替换 Java 中除 unicode 字母之外的任何内容
- php - 为什么我的 session_id() 没有被传递到下一页?
- vb.net - SelectCommand 属性在调用“填充”之前尚未初始化 - Visual Studio 2010
- python - 尺寸错误,在具有输入形状的 seq2seq 模型(操作:“添加”)中:[512,64]、[5739,64]
- sql - unicode 类型的 Oracle SQL regexp_like
- python - Python模拟失败调用断言
- html - 如何显示
- c# - Identity Server 根据 ResourceOwnerPassword Validator 中生成的 Guid 添加声明
- c++ - 如何使用 Bazel 在 Windows 上使用 C++ API 库进行编程?