Logistic regression can be used for this and the function glm () in R language provides this functionality.