comorbidity score calculator

It would be easier to help you with a reprex, and to include the full error messages.

In particular, which package does the comorbidity() function come from, this one?

The id is probably important, you might want to add one. Based on the vignette, your data.frame new1 should have, for each row, a diagnostic code associated with the patient. The same patient can appear in multiple rows. So, without an ID, you can't know which diagnostic code is associated with each patient, you don't have any data, just a collection of diagnostic codes that may or may not come from the same patients.

Since you seem to have 40 diagnostic columns in new1, perhaps the current structure of new1 is one row per patient, one column per code? In that case you can get to the correct format using pivot_longer(). Something like:

# add an id column
new1$id <- 1:nrow(new1)

# pivot to long format
new1_long <- pivot_longer(-id, names_to = "diag_number", values_to = "diag_code")

comorbidity(new1_long, id = "id", code = "diag_code")

(you probably need to modify this code depending on what your data really looks like)