I have a data.frame which contains json data:
dat1 = data.frame(id = 001, name = "Mac", score = '{"math":5}', date = '{"date1":"2018-01-19","date2":"2018-01-20"}')
dat2 = data.frame(id = 002, name = "Eric", score = '{"math":7}', date = '{"date1":"2018-01-18","date2":"2018-01-20"}')
dat = rbind(dat1, dat2)
And I want to get the following data.frame:
# id name score.math date.date1 date.date2
# 1 1 Mac 5 2018-01-19 2018-01-20
# 2 2 Eric 7 2018-01-18 2018-01-20
I want to use jsonlite::fromJSON first and rbind data then.
regexecandregmatchesto convert the date and score fields to the required object types. First, usedata.table::rbindlist(list(dat1, dat2), use.names = T, fill = T)to get a combined data.table and then call the function on the two columns.