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

R ProgrammingServer Side ProgrammingProgramming

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
raja
Published on 06-Jul-2020 14:34:18
Advertisements