I have a dataframe with 1 column and 1 value
df <- data.frame(type = c("recommended: 882, meh: 501, exceptional: 283, skip: 185"),
stringsAsFactors=FALSE)
I am trying to convert this type column into multiple individual columns of comments with their count
My desired output is
recommended meh exceptional skip
882 501 283 185
I am not able to extract the number from the string instead doing it this way
df %>% mutate(ind = row_number()) %>%
separate_rows(type, sep=",") %>%
#mutate(f = ifelse(is.na(f),0, f)) %>%
count(ind, type) %>%
spread(type, n, fill = 0) %>%
as.data.frame()
Can someone point me in the right direction?