假设A
和B
是两个dataframes
,最快的方法是:
找到A>0
and
B<0
的实例?即A
大于零,前提是B
小于零。
[两个dataframes
具有相等的尺寸,非常大(>70GB
),并且对column1
中的A
和coulmn1
中的B
等进行了操作。
A=c(-31.621, -40.149, -21.519, -33.773, -34.023, -38.345, -39.238,
-30.221, -22.278, 27.055)
B=c(-29.321, -26.398, -25.663, -26.423, -23.721, -17.418, -15.979,
-21.927, -16.398, -21.084)
这是您要寻找的吗?
library(tibble)
library(dplyr)
A <- c(-31.621, -40.149, -21.519, -33.773, -34.023, -38.345, -39.238,
-30.221, -22.278, 27.055) %>%
enframe(name = "ID")
B <- c(-29.321, -26.398, -25.663, -26.423, -23.721, -17.418, -15.979,
-21.927, -16.398, -21.084) %>%
enframe(name = "ID")
A %>%
left_join(., B, by = "ID", suffix = c("_A", "_B")) %>%
mutate(condition = case_when(value_A > 0 & value_B < 0 ~ T,
TRUE ~ F))
#> # A tibble: 10 x 4
#> ID value_A value_B condition
#> <int> <dbl> <dbl> <lgl>
#> 1 1 -31.6 -29.3 FALSE
#> 2 2 -40.1 -26.4 FALSE
#> 3 3 -21.5 -25.7 FALSE
#> 4 4 -33.8 -26.4 FALSE
#> 5 5 -34.0 -23.7 FALSE
#> 6 6 -38.3 -17.4 FALSE
#> 7 7 -39.2 -16.0 FALSE
#> 8 8 -30.2 -21.9 FALSE
#> 9 9 -22.3 -16.4 FALSE
#> 10 10 27.1 -21.1 TRUE
由reprex package(v0.3.0)在2020-02-25创建