- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个与此线程类似的问题:
Search across multiple columns with a regular expression and extract the match
让我们以鸢尾花数据集为例。我想根据几列中的值过滤数据:假设 >=4 在名称以“.Length”结尾的 cols 中。 IRL 数据比这个 reprex 复杂得多,这就是为什么我想在 cols 中使用正则表达式而不是通过它们的索引一个一个地挑选它们。
尝试了多种方式,包括以下几种:
filtered <- iris %>% dplyr::filter(across(matches('.Length')>=4))
没有用。请帮忙。
最佳答案
使用 dplyr::if_all
你可以:
library(dplyr)
iris1 <- iris %>%
filter(if_all(matches(".Length"), ~ .x >= 4))
str(iris1)
#> 'data.frame': 89 obs. of 5 variables:
#> $ Sepal.Length: num 7 6.4 6.9 5.5 6.5 5.7 6.3 6.6 5.9 6 ...
#> $ Sepal.Width : num 3.2 3.2 3.1 2.3 2.8 2.8 3.3 2.9 3 2.2 ...
#> $ Petal.Length: num 4.7 4.5 4.9 4 4.6 4.5 4.7 4.6 4.2 4 ...
#> $ Petal.Width : num 1.4 1.5 1.5 1.3 1.5 1.3 1.6 1.3 1.5 1 ...
#> $ Species : Factor w/ 3 levels "setosa","versicolor",..: 2 2 2 2 2 2 2 2 2 2 ...
关于r - 使用正则表达式有条件地过滤多列以选择colnames R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70563703/
我想知道如何将数据框的列名替换为原始列名中的唯一字符串? > colnames(df.iso) [1] "../trimmed/100G.tally.fasta" "../trimmed/100R.
我在一个函数中有一个 SELECT 子句,在该子句中我连接了两个表,以查找距离用户一定距离内且当前营业的餐馆。出于某种原因,当我运行这个函数时,我得到以下信息错误: ERROR: column "di
在我的 mvc jqgrid 代码中,colnames 和 colmodel 返回相同长度的 col。但是当运行应用程序时,我收到此错误。有什么帮助吗? 代码: public WeekColumns
我想重命名 data.frame 中的列名, > x=data.frame(name=c("n1","n2"),sex=c("F","M")) > colnames(x[1])="Name" > x
是否有更简单的(即一行代码而不是两行!)方法来执行以下操作: results setNames function (object = nm, nm) { names(object) <- n
我的应用程序将数据从 excel 读取到数据框中。然后它转置数据(感谢excel),然后构建一个数据框。 我想用第一行的内容替换在读取过程中分配的列名。 这是我尝试替换列名的方法。这似乎是执行此操作的
我的源 xml 看起来像: Test Test Test Test Test Test Test
我已经多次使用此功能,但直到现在才想到“它为什么有效?”。R 的 colnames() 函数如何为数据框分配新的列名称?我的意思是我了解 colnames(df) 将如何返回数据框的列名称。但它如何也
我有一个数据框,前 3 行有一些元数据,我需要跳过。但这样做也会影响值列的列名。 我该怎么做才能避免在 excel 上打开每个 CSV 并手动删除这些行? 这是 CSV 在 Excel 中打开时的样子
我有以下代码: library(dplyr) df % left_join(., panel_info, by = "PANID") %>% left_join(., prod_0106, b
我在我的数据库中存储了一个消息列表(这样如果我崩溃了我就不会丢失它们)。 但是当我把它们拉出来的时候,我需要把它们一 block 一 block 地按顺序拉出来。 我正在寻找的是一个查询,它将为我提供
假设我有以下简化表,其中分别包含动态列 a_x(其中 x 是索引,例如 0、1、2、3、4...)和 b_x。 a 列数始终等于 b 列数,但总列数可以是动态的(不总是 3 个 a 和3 b)。为了更
假设我有一个 df > editor A B C D E F G H I J User1 1 0 5 6 5 6 5 6 2 6 Use
我有一个关于 colnames 的问题基础包中的函数 假设您有一个 data.frame,如下所示: df colnames(df)[1] colnames(df)[1] [1] "test" c
我有一个页面,当用户单击一匹马以查看该马的更多信息(通过 mysql 表中的 ID 号引用)时,它只返回第一条记录,而不是您选择的记录。页面是http://www.cbarlranch.com/?pg
我正在审查某人的代码并遇到了这种选择语法: SELECT (Test_ID) id, (Test_Host) host, (Test_Port) port FROM Test_Connection 我
我有一个包含 76 列相同数量物种的数据框,我想使用循环在不同的地 block 中绘制每个物种。但是,我想使用 colnames 来获取每个带有每个物种名称的地 block 。有人可以帮助我解决我的问
我正在尝试在 data.frame 上使用应用和用户定义的函数。在函数内部,我想使用列名(作为绘图的标题),但 apply 似乎去除了列名并仅传递了一个向量。 MWE: trialData <- da
我正在制作一个函数来创建表格,我需要一些涉及格式化的条件规则。一个将基于列名,但是当我使用 as.formula 发送它时似乎已经结束了。我在这里做了一个例子: library(tidyverse)
我正在尝试对数据框中的多个列进行 group_by,但无法在 group_by 函数中写出每个列名,因此我想将列名称为向量,如下所示: cols % filter(disp % group_by(co
我是一名优秀的程序员,十分优秀!