r - Check only if a value is present in a vector
问题描述
In a dataframe column, can we check only if a value is present. Example, asd$a
has 3 values.
So if I want see if it contains only "A", it should return true. In below case , it should return FALSE, since it contains "A","B" and "C". Similarly, We need to check if it contains only "A" and "C" and so on
asd <- data.frame(a = c("A","B","C"), b = c(1,2,3))
解决方案
只需在它周围放置一个all(df$a=="A")
。第二种选择all(df$a=="A" | df$a=="B")
。