r - R - 确认 2 列中的数据
问题描述
我正在尝试在 R 中编写以下逻辑。
if(there exists data in column A row A)
then(there must be data in column B row A)
有这个功能吗?
预期输出:
Some sort of text here.
FALSE
解决方案
dat1
A B
1 3 NA
2 NA 2
3 NA NA
4 NA 10
5 NA 5
6 8 NA
7 NA 8
8 6 4
9 10 1
10 1 NA
g = which(is.na(dat1),T)
replace(dat1,g[!(duplicated(g[,1],fromLast = T)|duplicated(g[,1])),],"FALSE")
A B
1 3 FALSE
2 FALSE 2
3 <NA> <NA>
4 FALSE 10
5 FALSE 5
6 8 FALSE
7 FALSE 8
8 6 4
9 10 1
10 1 FALSE
推荐阅读
- python - 对象检测错误:ImportError: libcblas.so.3: cannot open shared object file: no such file or directory
- git - 使用 git 命令更新所有 git 子模块路径的脚本(不是通过编辑 .gitmodules 文件)
- firebase - 拒绝阅读未发布的帖子 firebase 相同的集合
- c# - 登录xamarin表单后如何将主页设置为永久?
- azure - 流分析输出到 ARM 模板中的 Synapse Analytics
- javascript - 实现放置自动完成地址表单时无法读取未定义的属性“address_components”
- python - 如何并行处理 10,000 个文件的 python 脚本?
- python-3.x - 如何根据其他数据框列替换熊猫列值
- performance - 使用字符列表进行模式匹配
- typescript - 如何在 Typescript 类型检查期间抛出类型错误