Assuming that d
is as in the Note the end, create a function decimals
that returns TRUE for each element of its vector argument that has 2+ decimals (or FALSE otherwise) or if given a data frame argument applies that to each column. Use it to subset d
.
decimals <- function(x) sapply(x, grepl, pattern = r"{.dd}")
subset(d, decimals(x) & decimals(y))
## x y
## 1 112.210 234.5110
## 2 56.220 1.1111
## 3 3.456 2.3100
or if there can be an unknown number of numeric columns in d
or different column names then replace the last line with:
subset(d, apply(decimals(d), 1, all))
Note
Lines <- "
x y
112.21 234.511
56.22 1.1111
3.456 2.31
1.1 2.4567
3.411 4.5"
d <- read.table(text = Lines, header = TRUE)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…