r - collapse text by 2 ID's in a row -


i have question similar topic: "collapse text group in data frame [duplicate]"

group text a1 a2 a3 b b1 b b2 c c1 c c2 c c3 c c4 

i collapse 2 sequential id's (not whole id group)

group text a1a2 a2a3 b b1b2 c c1c2 c c2c3 c c3c4 

alternative tidyverse answer:

library(tidyverse) dat %>%   group_by(group) %>%   mutate(text=paste0(lag(text),text)) %>% slice(-1) 

using data.table:

library(data.table) setdt(dat) dat[, paste0(shift(text,1), text)[-1], by=group]  #   group   v1 #1:     a1a2 #2:     a2a3 #3:     b b1b2 #4:     c c1c2 #5:     c c2c3 #6:     c c3c4 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -