-2

I have a data frame with cols as follows:

name age hobbies abc 10 video games,football,swimming

which i would like to convert this into some thing like this

name age hobbies abc 10 videogames abc 10 football abc 10 swimming

see this if you dont understand

Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
vaibhav krishna
  • 227
  • 2
  • 4

2 Answers2

1

You can use cSplit from splitstackshape

cSplit(indt = df1, splitCols = "hobbies", sep = ",", direction = "long")
akrun
  • 789,025
  • 32
  • 460
  • 575
Jason Mathews
  • 735
  • 3
  • 13
0

An option would be separate_rows

library(tidyverse)
df1 %>%
    separate_rows(hobbies)
#  name   age  hobbies
#1   10 video    games
#2   10 video football
#3   10 video swimming

data

df1 <- structure(list(name = 10L, age = "video", 
hobbies = "games,football,swimming"), class = "data.frame", row.names = "abc")
akrun
  • 789,025
  • 32
  • 460
  • 575