r - 基于 R 中列集中的值的子集

标签 r

我有以下数据框:

ID   Degree1   Degree2   Degree3   Degree4   Degree6   Degree6
1001 10        5         0         6         4         12 
1002 0         0         0         0         0         0 
1003 0         2         0         0         9         0 

我想要在所有 6 度中仅包含值 0 的行。我检查了以下命令但没有起作用:

subset(data, data$Degree1:Degree6 == 0)

有人可以帮我解决这个问题吗?

最佳答案

我们可以使用rowSums

data[rowSums(data[-1]==0)==6,]

或者使用否定!

data[!rowSums(data[-1]!=0),]

关于r - 基于 R 中列集中的值的子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42632218/

相关文章:

r - ggplot2饼图标签的错误位置

r - 将 dplyr slice_sample 函数转换为基础 R

r - 如何使用 R 从托管在 AWS ubuntu 服务器上的 Rstudio Connect 访问托管在 Azure Windows VM 上的 SQL Server 数据库?

r - 使用 `colnames` 的数值使用 `dplyr` 的 `mutate_at` 或替代方法重新计算 data.frame 中的列

r - 为什么向量由 ':' 整数创建?

r - 使用循环添加顺序值

r - 日期转换 : Converting dates that contain day of the week to a normal date format

r - scale_y_discrete 忽略中断/标签

r - `purrr::pmap()` 是否忽略了额外的列?

c - 了解如何在 R 中处理 .Internal C 函数