简体   繁体   English

如何根据包含 _________.000 小数的“版本”列过滤数据集?

[英]how do I filter dataset based on "Version" column containing _________.000 decimal?

I have a dataset where I am trying to filter based on 3 different columns.我有一个数据集,我试图根据 3 个不同的列进行过滤。

I have the 2 columns that have character values figured out by doing: filter(TRANSACTION_TYPE,= "ABC", CUSTOMER_CODE == "123") however.我有 2 列的字符值是通过执行以下操作计算出来的: filter(TRANSACTION_TYPE,= "ABC", CUSTOMER_CODE == "123") 但是。 I have a "VERSION" column where there will be multiple versions for each customer which will then duplicate my $ amount.我有一个“版本”列,其中每个客户都有多个版本,然后将复制我的 $ 金额。 I want to filter on only the VERSION that contains ".000" as decimal since the.000 represents the final and most accurate version, For example.我只想过滤包含“.000”作为十进制的版本,因为 .000 代表最终和最准确的版本,例如。 VERSION can = 20220901.000 and 20220901.002 ( enter image description here ), 20220901.003, etc. However the numbers before the decimal will always change so I can't filter on it to equal this 20220901 as it will change by day. VERSION 可以 = 20220901.000 和 20220901.002(在此处输入图像描述)、20220901.003 等。但是小数点前的数字总是会变化,所以我无法对其进行过滤以使其等于 20220901,因为它每天都会变化。

I hope I was clear enough, thank you!我希望我足够清楚,谢谢!

Sample data:样本数据:

quux <- data.frame(VERS_chr = c("20220901.000","20220901.002","20220901.000","20220901.002"),
                   VERS_num = c(20220901.000,20220901.002,20220901.000,20220901.002))

If is.character(quux$VERSION) is true in your data, then如果is.character(quux$VERSION)在您的数据中为真,则

dplyr::filter(quux, grepl("\\.000$", VERS_chr))
#       VERS_chr VERS_num
# 1 20220901.000 20220901
# 2 20220901.000 20220901

Explanation:解释:

  • "\\.000$" matches the literal period . "\\.000$"匹配文字句点. (it needs to be escaped since it's a regex reserved symbol) followed by three literal zeroes 000 , at the end of string ( $ ). (它需要转义,因为它是一个正则表达式保留符号)后跟三个文字零000 ,在字符串 ( $ ) 的末尾。 See https://stackoverflow.com/a/22944075/3358272 for more info on regex.有关正则表达式的更多信息,请参阅https://stackoverflow.com/a/22944075/3358272

If it is false (and it is not a factor ), then如果它是假的(并且它不是一个factor ),那么

dplyr::filter(quux, abs(VERS_num %% 1) < 1e-3)
#       VERS_chr VERS_num
# 1 20220901.000 20220901
# 2 20220901.000 20220901

Explanation:解释:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何基于列中的公共值过滤两个矩阵? - How do I filter two matrices based on common values in a column? 如何根据在特定天数内从一个值到另一个值来过滤我的数据集? - How do I filter my dataset based on going from one value to another within a specific number of days? 如何根据列中的值过滤掉数据,同时捕获另一列中的最小日期条件? - How do I filter out data based on a value in column while capturing minimum date criteria in another column? 如何将包含日期2019的列添加到数据集? - How to add a column containing the date of 2019 to a dataset? 如何根据R中另一个数据框中的列值过滤数据框? - how do i filter a dataframe based on the values of a column in another dataframe in R? 如何根据字符串的第一个和第三个字符过滤一列字符串? - How do I filter a column of character strings based on their first and 3rd characters? 如何过滤数据框中的数据并使用循环根据它更改列的单元格值? - How do I filter data in data frame and change column's cell values based on it using a loop? 如何根据满足特定条件的所有行过滤具有匹配列值的多行? [R] - How do I filter multiple rows with matching column values based on all rows meeting a certain condition? [R] 如何根据r中的最后两个小数进行过滤? - How to filter based on last two decimal in r? 如何根据另一个数据集中的值过滤一个数据集中的日期和时间 - How to filter date and time in one dataset based on values in another dataset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM