Concern with startsWith and multiple patterns in R
问题 I noticed a problem or a concern with the startsWith() function. The following code displays two different selection. The first one behave normally which is this chunk of code: dt_test <- data.table(a = c("abcd", "poo", "abla", "ba"), id = c(1,2,3, 4)) dt_test[startsWith(a, c("ab", "ao")),id] # [1] 1 3 startsWith(dt_test$a, c("ab", "ao")) # TRUE FALSE TRUE FALSE And if you noticed, this one only selects the first one which is counter intuitive since id 2 and 4 are supposed to be TRUE dt_test