This is a little bit of a guess, but I think what you're looking for is setting all the factor levels in your test set explicitly:
for (x in note_names) {
levels(test[[x]]) <- c("no","yes")}
}
While it is generally best practice to use factors rather than dummy variables or integer codes to represent categorical variables in R (this is what they're meant for, and it means you don't have to remember or have a separate code book to know that e.g. 1=male, 2=female), in this case I think you might as well code 'absent' as 0 and 'present' as 1 - this is what any statistical/ML method is going to transform your categorical variable into anyway, and it's unambiguous.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…