-2

I have the following data frame.

x <- data.frame("Item" = c('Item1','Item1','Item2','Item2'), "Name" = c("This row and","the next should be grouped together","Also this row and","the next should be grouped together"))

I want the output to be as follows.

x2 <- data.frame("Item" = c('Item1','Item2'), "Name" = c("This row and the 
next should be grouped together","Also this row and the next should be 
grouped together"))

I have a large data-frame of 10000 rows and I am new to R.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Abhishek Kulkarni
  • 654
  • 1
  • 8
  • 20

1 Answers1

1

You can use dplyr and group your Item variable and concatenate the text. I collapsed by an empty string but ', ' or ';' would be also possible

library(dplyr)

x %>%
  group_by(Item) %>%
  summarise(Name=paste0(Name, collapse=''))
drmariod
  • 11,106
  • 16
  • 64
  • 110