Suppose I have the following data and a vector of column names
dt <- data.table(id = letters[1:10], amount = 1:10, id2 = c(rep('a',5),rep('b',5)),test=rep('a',10))
cols <- c('id','id2','test')
what I'm trying to do is select rows where all columns in the vector have the same specific value like
dt[id=='a' & id2=='a' & test == 'a']
but using the vector cols. Is there a way to do it?
Note: I need to find a way to do it using data.table or base R without making comparisons between the columns like
dt[id==id2 & id==test & id2==test]
dtneed to be a data.table or can we use dataframe as well?data.table