使用%in%
运算符,这个子集化操作wantedSubset
的等价物是什么?
dataset <- data.frame(
"V1"=c(1,2,3,4,5,6,7,8),
"V2"=c("green","yellow","blue","red","purple","black","white","gray")
)
# subset all cells containing the value 3 or the value "blue"
wantedSubset <- dataset == 3 | dataset == "blue"
我希望使用wantedSubset
运算符以不同的方式执行%in%
操作。怎么&amp;为什么我能做到这一点? (似乎%in
应用于整个列而不是每个单元格值?)
# will not return wanted result
dataset %in% c("3","blue")