Convert “type” column into multiple individual columns of comments with their count

First split on comma into separate rows, then split on colon into separate columns and then get data in wide format.

library(tidyr)
df %>%
  separate_rows(type, sep = ',\\s*') %>%
  separate(type, c('type', 'value'), sep = ':\\s*', convert = TRUE) %>%
  pivot_wider(names_from = type, values_from = value)

#   recommended   meh exceptional  skip
#        <int> <int>       <int> <int>
#1         882   501         283   185

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top