-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
  • 74,560
  • 11
  • 127
  • 189

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
  • 10,480
  • 12
  • 53
  • 107