Hi, everyone! I'm trying to write some code that returns a new dataframe without certain rows if a condition is true. In the tibble below, I have the study name, the test used in the study, and code that corresponds to the type of test used in the study. To reduce dependencies in the dataset, I want to write some code that tells me whether or not, for each study in the data, the study has both a total test score ("2") and score for only a subsection ("1") of the total test ("reading", "writing", etc.). So, I want to write code that says, "For each study, if the study has both a 2 and a 1, return a new df without the 2's". Any help with this? Thanks!
Thanks for your reply! Once I figure this bit of code out, I can finally wrap up some edits to my dissertation. So, I appreciate your help!
Yes! This totally works! However, is there a way for me to filter rows from distinct studies if that study has both Code == 1 and Code == 2? I need the conditional execution because, with my larger dataset, sometimes a study ends up with just a 1 or just a 2 after running some other code. I just really want to avoid manually checking the final dataset!
Your sample data frame only has studies that fulfill the condition, so the rows with Code==2 for those studies are deleted. For studies that don't have at least one row with Code==1 and at least one row with Code==2, all rows will be returned.
Yaaaaay! Thank you both so much! I'm really so thankful that folks like you exist and contribute to the RStudio Community! You've both made my life so much easier. This bit of code was all I needed to really finish wrapping up my dissertation. Thank you!!!!!!!