Hi everyone, thank you for all of your help in this forum-truly invaluable!
So, to provide background on the code below, I have a dataframe where the columns are a bunch of drug names. The drug names can either have "C", "P", or "no value/NA" in them. I had asked for help earlier in filtering the data such that only certain drugs would equal "C".
In the example below, methamphetamine, cocaine, and fentanyl equal "C", and all the other drugs cannot equal C or P (no value/NA is fine).
MFCALONE <- MEC_2013_up%>%filter(Fentanyl=="C",
Cocaine=="C",
Methamphetamine=="C",
across(c(-Fentanyl,-Cocaine,-Methamphetamine), ~!.x %in% c("C","P")))
My problem is that I am having trouble understanding exactly what the last line is doing.
From my understanding of the "across" function, the first argument is specifying the columns to take from (in this case, every column but fentanyl, cocaine, and methamphetamine). However, I am unclear on what the "~!.x" as well as the %in% is doing. Could someone provide an explanation? I was still unclear after looking up the documentation on the "across" function.
Thank you!