I\'ve got a data.frame with key/value string column containing information about features and their values for a set of users. Something like this:
data.frame
key/value string
You can use dplyr and tidyr:
dplyr
tidyr
library(dplyr); library(tidyr) data %>% mutate(str = strsplit(str, ",")) %>% unnest(str) %>% separate(str, into = c('var', 'val'), sep = ":") %>% spread(var, val, fill = 0) # id statid 7 a b c # 1 1 s003e 2 1 0 0 # 2 2 s093u 0 1 0 4 # 3 3 s085t 0 3 5 33