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
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
You can use cSplit
from splitstackshape
cSplit(indt = df1, splitCols = "hobbies", sep = ",", direction = "long")
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
df1 <- structure(list(name = 10L, age = "video",
hobbies = "games,football,swimming"), class = "data.frame", row.names = "abc")