Input table
Patients Hospital Drug Response
1 AAA a Good
1 AAA a Bad
2 BBB a Bad
3 CCC b Good
4 CCC c Bad
5 DDD e undefined
Output file
Patients Hospital Drug Response
1 AAA a 1
1 AAA a -1
2 BBB a -1
3 CCC b 1
4 CCC c -1
5 DDD e
How to replace 3 texts in one column to number and blank?
"good in Reponse column" to "1" "bad in Reponse column" to "-1" "undefined in Reponse column" to " "
Data:
structure(list(Patients = c(1L, 1L, 2L, 3L, 4L, 5L), Hospital = structure(c(1L,
1L, 2L, 3L, 3L, 4L), .Label = c("AAA", "BBB", "CCC", "DDD"), class = "factor"),
Drug = structure(c(1L, 1L, 1L, 2L, 3L, 4L), .Label = c("a",
"b", "c", "e"), class = "factor"), Response = structure(c(2L,
1L, 1L, 2L, 1L, 3L), .Label = c("Bad", "Good", "undefined"
), class = "factor")), .Names = c("Patients", "Hospital",
"Drug", "Response"), class = "data.frame", row.names = c(NA,
-6L))