-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
  • 377,200
  • 20
  • 156
  • 213
vaibhav krishna
  • 267
  • 2
  • 4

2 Answers2

1

You can use cSplit from splitstackshape

cSplit(indt = df1, splitCols = "hobbies", sep = ",", direction = "long")
akrun
  • 874,273
  • 37
  • 540
  • 662
Jason Mathews
  • 765
  • 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
  • 874,273
  • 37
  • 540
  • 662