說我有這個數據裏面,加入/合併兩列數據幀
(df <- data.frame(col1 = c('My','Your','His','Thir'), col2 = c('Cat','Dog','Fish','Dog')))
col1 col2
1 My Cat
2 Your Dog
3 His Fish
4 Thir Dog
,我想列組合在一起這樣
`some magic`
col1 col2 col3
1 My Cat My Cat
2 Your Dog Your Dog
3 His Fish His Fish
4 Thir Dog Thir Dog
我該怎麼辦?甚至用逗號(,)這樣,
`some magic`
col1 col2 col3
1 My Cat My, Cat
2 Your Dog Your, Dog
3 His Fish His, Fish
4 Thir Dog Thir, Dog
一個簡單的包裝親愛的Erik Shilts,工作就像一個魅力。謝謝! –
如果我們正在處理空值,該怎麼辦?我們如何處理額外的逗號 – Saksham
我仍在等待您的回覆。假設數據是'col1'爲空,'col2'爲cat。結果值不會是',貓'。如何處理?我只需要'貓'。如果我們玩多列,結果甚至可能是',,貓,,狗' – Saksham