I have a very large data.table with the structure below:
variant ID1 ID2 ID3 ID4 .... ID80000
123 0 1 2 1 0
321 1 2 1 1 1
543 1 1 2 1 1
6542 1 0 0 1 0
243 1 0 2 1 1
654 0 1 1 2 1
342 1 2 1 2 1
I would like to add a row with a 0 or 1 dependant on whether the ID in a string is present in the above table.
Say I have the a list: a <- c("ID42", "ID4")
The desired output would be:
variant ID1 ID2 ID3 ID4 .... ID80000
123 0 1 2 1 0
321 1 2 1 1 1
543 1 1 2 1 1
6542 1 0 0 1 0
243 1 0 2 1 1
654 0 1 1 2 1
342 1 2 1 2 1
present 0 1 0 1 0
A bit like this question but in rows: Create new conditional column if string contains elements from list
I have tried:
df$present <- colnames(df) %in% id_list
But I get an error as it says there are too many rows.
Many thanks for your help
Would an ifelse be helpful here?