I have a dataset with different columns. Looks like that
df <- data.frame(PatientID = c("0002" ,"0004", "0005", "0006" ,"0009" ,"0010" ,"0018", "0019" ,"0020" ,"0027", "0039" ,"0041" ,"0042", "0043" ,"0044" ,"0045", "0046", "0047" ,"0048" ,"0049", "0055"),
A = c(987.805 , 977.146 , 790.809 , 964.315 ,1014.020 , 952.311 , 992.967 , 950.797 , 958.975 ,960.712 ,958.117 , 947.465 , 902.852 , 961.417, 985.124 ,994.178 , 930.141 ,1007.790 , 948.848, 1027.110 , 999.414),
B = c(998.988 , 972.606 , 998.680 , 955.037 , 972.941 ,1020.560 , 947.751 ,1029.560 , 955.540 , 911.606 , 964.039 , NA, 988.087 , 902.367 , 959.338 ,1029.050 , 925.162 , 987.374 ,1066.400 ,957.512 , 917.597),
C = c( 975.634 , 987.140 , 961.810 , 929.466 , 978.166, 1005.820 ,925.752 , 969.469 , 943.398 ,936.034, 965.292 , 996.404 , 920.610 , 967.047 ,986.565 , 913.517 , 893.428 , 921.606 , 976.192 , 929.590 ,950.493),
D = c(975.634 , 987.140 , 961.810 , 929.466 , 978.166, 1005.820 , 925.752 , 969.469 ,943.398 , 936.034 , 965.292 , 996.404 , 920.610 , 967.047 , 986.565 , 913.517 , 893.428 , 921.606 , 976.192 , 929.590 , 950.493),
E = c(1006.330, 1028.070 , 975.554 , 954.274 ,1005.910 ,949.969 , 992.820 , 977.048 ,934.407 , 948.913 , 944.578 , 917.564 , 975.301, 961.375 ,955.296 , 961.128 ,998.119 ,1009.110 , 994.891 ,1000.170 ,982.763),
G= c(951.684 , 958.990 , 944.432 , 944.654 , 924.680 , 955.927 , 972.674 , 949.384 ,973.348 , 984.392 , 943.894 , 961.468 , 995.368 , 994.997 , 973.175 , 979.454 , 952.605 , 930.744 , NA, 1015.150 , 956.507), stringsAsFactors = F)
Basically what I need is to create an extra column that will be called above threshold, That will be TRUE/FALSE based on the following conditions:
To be TRUE, the patient need to have values above thresholds in any 3 out of the 6 columns (A, B, C, D, E or G), the thresholds are:
- for A and B -> 990
- for C and D -> 1000
- for E and G -> 1005
otherwise is FALSE
Basically 3 or more columns need to be TRUE for the final column to be TRUE. The output would look like this (above threshold == TRUE are painted in green):
How could I set this up? - I hope this is clear, but ask away if is not!
Many thanks!

Aucun commentaire:
Enregistrer un commentaire