空索引向量的补码是空索引向量 [英] Complement of empty index vector is empty index vector

查看:79
本文介绍了空索引向量的补码是空索引向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过在索引向量前面使用 - (减号)从矢量中删除值。像这样:

I am removing values from a vector by using - (minus sign) in front of the index vector. Like this:

得分< - 得分[-indexes.to.delete]

有时 indices.to.delete vector为空,即N / A.因此,得分向量应保持不变。但是,当 indexes.to.delete 为空时,我得到空得分向量。

Sometimes indexes.to.delete vector is empty, that is N/A. So the scores vector should then remain unchanged. However, I am getting empty scores vector when indexes.to.delete is empty.

示例:

x <- c(1, 2, 3);
y <- c(4, 5, 6);
indexes.to.delete <- which(y < x); # will return empty vector
y <- y[-indexes.to.delete]; # returns empty y vector, but I want y stay untouched

我可以编写if语句来检查是否 indexes.to.delete 是空的,但我想知道是否有更简单的方法?

I could code an if statement checking whether indexes.to.delete is empty, but I am wondering if there is a simpler way?

推荐答案

也许使用;

x <- c(1, 2, 3)
y <- c(4, 5, 6)
y[!y<x]
> y[!y<x]
[1] 4 5 6

x <- c(1, 2, 3)
y <- c(4, 1, 6)
> y[!y<x]
[1] 4 6
>

这篇关于空索引向量的补码是空索引向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆