R中的[]
包只允许我使用&&
运算符选择一次使用一个简单逻辑测试的行。即使逻辑上等效的||
语句按预期工作,我也无法使用ifelse
或ifelse
运算符。这种限制有什么好的理由吗?它有简单,更冗长的解决方法,如&&
(以及模拟R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-unknown-cygwin (64-bit)
# --- Rest of startup message snipped. ---
> library(data.table)
data.table 1.10.4
# --- Rest of startup message snipped. ---
> dt <- data.table(a=1:6, b=11:16) # Make a sample data table.
> dt # Print the data table, for easy reference.
a b
1: 1 11
2: 2 12
3: 3 13
4: 4 14
5: 5 15
6: 6 16
> dt[a >= 3] # A single logical test works fine.
a b
1: 3 13
2: 4 14
3: 5 15
4: 6 16
> dt[((a >= 3) && (b <= 15))] # Conjunction with && returns zero rows.
Empty data.table (0 rows) of 2 cols: a,b
> dt[ifelse(a >= 3, b <= 15, FALSE)] # The equivalent ifelse call works.
a b
1: 3 13
2: 4 14
3: 5 15
> dt[((a <= 2) || (b >= 15))] # Disjunction with || returns every row.
a b
1: 1 11
2: 2 12
3: 3 13
4: 4 14
5: 5 15
6: 6 16
> dt[ifelse(a <= 2, TRUE, b >= 15)] # The equivalent ifelse call works.
a b
1: 1 11
2: 2 12
3: 5 15
4: 6 16
的方法链接),但它仍然令人恼火。
这是一个说明性终端会议的成绩单。
List<WebElements>