因此,使用下面的簡單數據框,我想創建一個新列,每個人的所有日期都用分號分隔。與Tidyr合併多列時處理空格和NA的問題
例如,使用Doug,應該看起來像 - 星期一;星期三;星期五
我想使用Tidyr的Unite函數,但是當我使用它時,我得到 - 星期一;;星期三;;星期五,因爲NA,它也可以是空格。有時在起始和結尾處都有分號。所以我希望有一種方法可以繼續使用「統一」,但通過正則表達式進行增強,這樣我最終可以在一週中的每一天以一個分號分隔開始,並且在開始或結束時不會出現分號。
我也想用Tidyr,Dplyr,Stringr等
Names<-c("Doug","Ken","Erin","Yuki","John")
Monday<-c("Monday"," "," ","Monday","Monday")
Tuesday<-c(" ","Tuesday","Tuesday"," ","Tuesday")
Wednesday<-c(" ","Wednesday","Wednesday","Wednesday"," ")
Thursday<-c(" "," "," "," ","Thursday")
Friday<-c(" "," "," "," ","Friday")
Days<-data.frame(Monday,Tuesday,Wednesday,Thursday,Friday)
Days<-Days%>%unite(BestDays,Monday,Tuesday,Wednesday,Thursday,Friday,sep="; ",remove=FALSE)
https://github.com/hadley/tidyr/issues/203 – Sumedh