-2

I have a data.table object where each row in the column "status" is filled with a list. How can I create a new data.table transforming its lists to columns:

Columns "as is":

status, done_ratio, created_on, updated_on, closed_on

Columns "to be":

status_id, status_name, done_ratio, created_on, updated_on, closed_on

Code used:

basic_data <- tickets[, .(status,done_ratio,created_on,updated_on,closed_on)]

Result of view(basic_data): http://diegoquirino.pro.br/printdetela/print_duvida_datatablelistcolumn.png

I'd like to have NOT a list, but ordinary columns: status_id, status_name

Thankfully for help.

  • 1
    Does the fact that you are posting pictures instead of code mean that you expect any prospective respondent to do the data entry and coding to create an example? – IRTFM Feb 27 '18 at 20:31
  • Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Feb 27 '18 at 21:20
  • Yes, it is. I expect any prospective to solve this problem, because I have the object in picture, a data.table. But, column "status" content is a list. I'd like to "transform" it in a new object, where these list items become columns. Is it possible to make this? – Carlos Diego Quirino Lima Feb 28 '18 at 16:32

1 Answers1

0

The following code attempts to the purpose (considering "tickets", object from picture):

# Collecting basic data
basic_data <- tickets[, .(done_ratio,created_on,updated_on,closed_on)]

status_data <- data.frame("status_id" = integer(),"status_name" = character())
# Fetching Status (each list)
for(status in tickets[,status]){
  status <- as.data.frame(rbind(status))
  names(status) <- c("status_id","status_name")
  status_data <- rbind(status_data,status)
}

status_data <- cbind(status_data,basic_data)