使用下面的示例,我想按CaseWorker分組數據幀,然後客戶端,然後爲每個客戶端組確定是否在「任務」與「任務2」中的任務列表相同。使用Dplyr的「group_by」創建組,然後使用Stringr查找組之間的差異
如果每個處於「任務2」但不是「任務」的任務都可以提取並顯示在新的列或數據框中,我會很高興有一個簡單的真或假,或更好。
所以基本上我需要確保「任務」和「任務2」爲每個客戶端包含相同的條目。
如果可能的話,我想堅持使用Dplyr和Stringr,或者至少留在Tidyverse中。我認爲有一種使用「group_by」和「str_detect」或其他一些Stringr功能以優雅的方式實現這一點的方法。
CaseWorker<-c("John","John","John","John","John","John","Melanie","Melanie","Melanie","Melanie","Melanie","Melanie")
Client<-c("Chris","Chris","Chris","Tom","Tom","Tom","Valerie","Valerie","Valerie","Tim","Tim","Tim")
Task<-c("Feed cat","Make dinner","Iron shirt","Make dinner","Do homework","Make lunch","Make dinner","Feed cat","Buy groceries","Do homework","Iron shirt","Make lunch")
Task2<-c("Feed cat","Make dinner","Iron shirt","Make dinner","Do homework","Feed cat","Make dinner","Feed cat","Iron shirt","Do homework","Iron shirt","Make lunch")
Df<-data.frame(CaseWorker,Client,Task,Task2)
感謝您的回答!我發佈了這個問題的「第二部分」,如果您有興趣也可以發佈一個更復雜但相似的問題。它以相同的問題名稱發佈,但在開始時使用「第2部分」。 – Mike