How to split a string column into multiple columns in R?



This can be done with the help of tidyr package.

Example

> library(tidyr) > data = data.frame(attr = c(1,5,12,17), type=c('class_and_memory','class_and_memory_2')) > data %>% + separate(type, c("class", "memory"), "_and_") attr class memory 1 1 class memory 2 5 class memory_2 3 12 class memory 4 17 class memory_2
Updated on: 2020-07-06T14:35:39+05:30

477 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements