I have a dataframe, “grp_wqdata, that is grouped by the vector “CHEMICAL_NAME”:
structure(list(SAMPLE_ID = c("Sampe 1", "Sampe 2", "Sampe 3",
"Sampe 4", "Sampe 5", "Sampe 6", "Sampe 7", "Sampe 8", "Sampe 9",
"Sampe 10", "Sampe 11", "Sampe 12"), CHEMICAL_NAME = c("LEAD",
"LEAD", "LEAD", "LEAD", "LEAD", "LEAD", "LEAD", "LEAD", "LEAD",
"LEAD", "LEAD", "LEAD"), REPORT_RESULT_VALUE = c(0.769, 0.512,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5), REPORT_METHOD_DETECTION_LIMIT = c("0.0100",
"0.0100", "0.500", "0.500", "0.500", "0.500", "0.500", "0.500",
"0.500", "0.500", "0.500", "0.500"), DETECT_FLAG = c("Y", "Y",
"N", "N", "N", "N", "N", "N", "N", "N", "N", "N")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -12L))
If the value in vector DETECT_FLAG is “N”, then I would like to replace the value that is in REPORT_RESULT_VALUE on that row with the value in REPORT_RESULT_LIMIT in that row.
I have tried the following:
ifelse(“N” %in% grp_wqdata$DETECT_FLAG,
replace(grp_wqdata$REPORT_RESULT_VALUE,
grp_wqdata$REPORT_RESULT_VALUE[match(grp_wqdata$DETECT_FLAG == “N”)],
grp_wqdata$REPORT_RESULT_LIMIT[match(grp_wqdata$DETECT_FLAG == “N”)]),
-999)#end of ifelse
but I continue to get the error
"Error in match(grp_wqdata$DETECT_FLAG == "N") :
argument "table" is missing, with no default"
Does anyone have any suggestions for doing this without a for loop? Thank you.