{"action":"created","issue":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/1418","repository_url":"https://api.github.com/repos/Rdatatable/data.table","labels_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1418/labels{/name}","comments_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1418/comments","events_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1418/events","html_url":"https://github.com/Rdatatable/data.table/issues/1418","id":114359929,"number":1418,"title":"as.data.table.array - convert multidimensional array into data.table","user":{"login":"jangorecki","id":3627377,"avatar_url":"https://avatars.githubusercontent.com/u/3627377?v=3","gravatar_id":"","url":"https://api.github.com/users/jangorecki","html_url":"https://github.com/jangorecki","followers_url":"https://api.github.com/users/jangorecki/followers","following_url":"https://api.github.com/users/jangorecki/following{/other_user}","gists_url":"https://api.github.com/users/jangorecki/gists{/gist_id}","starred_url":"https://api.github.com/users/jangorecki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jangorecki/subscriptions","organizations_url":"https://api.github.com/users/jangorecki/orgs","repos_url":"https://api.github.com/users/jangorecki/repos","events_url":"https://api.github.com/users/jangorecki/events{/privacy}","received_events_url":"https://api.github.com/users/jangorecki/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Rdatatable/data.table/labels/feature%20request","name":"feature request","color":"009800"}],"state":"open","locked":false,"assignee":{"login":"jangorecki","id":3627377,"avatar_url":"https://avatars.githubusercontent.com/u/3627377?v=3","gravatar_id":"","url":"https://api.github.com/users/jangorecki","html_url":"https://github.com/jangorecki","followers_url":"https://api.github.com/users/jangorecki/followers","following_url":"https://api.github.com/users/jangorecki/following{/other_user}","gists_url":"https://api.github.com/users/jangorecki/gists{/gist_id}","starred_url":"https://api.github.com/users/jangorecki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jangorecki/subscriptions","organizations_url":"https://api.github.com/users/jangorecki/orgs","repos_url":"https://api.github.com/users/jangorecki/repos","events_url":"https://api.github.com/users/jangorecki/events{/privacy}","received_events_url":"https://api.github.com/users/jangorecki/received_events","type":"User","site_admin":false},"milestone":null,"comments":8,"created_at":"2015-10-30T21:33:35Z","updated_at":"2016-03-25T11:57:49Z","closed_at":null,"body":"FR for multidimensional array conversion to data.table.\r\nLogic behind conversion is to lookup value from array for each combination of dimensions. Rationale is not only the similar API on subset of array/data.table (see below examples) but the underlying organization of data. It basically reduce array dimensions to tabular structure keeping all the relations between dimensions and corresponding value of a measure - so losslessly.\r\nBelow solution is likely to be inefficient due to lookup value from array for each group. The `j` argument may looks scary but it simply builds following call `.(value = x[color, year, country])` to perform subset `x` array for each group.\r\n```r\r\nlibrary(data.table)\r\nset.seed(1)\r\n\r\n# array\r\nar = array(rnorm(8,10,5), rep(2,3), dimnames = list(color = c(\"green\",\"red\"), year = c(\"2014\",\"2015\"), country = c(\"UK\",\"IN\")))\r\nar[\"green\",\"2015\",]\r\nar[\"green\",c(\"2014\",\"2015\"),]\r\n\r\n# data.table\r\nas.data.table.array = function(x) do.call(CJ, dimnames(x))[, .(value = eval(as.call(lapply(c(\"[\",\"x\", names(dimnames(x))), as.symbol)))),, keyby = c(names(dimnames(x)))]\r\ndt = as.data.table.array(ar)\r\ndt[J(\"green\",\"2015\")]\r\ndt[J(\"green\", c(\"2014\",\"2015\"))]\r\n```\r\nAre you willing to merge such feature? Any suggestions for improvement?\r\nQuestion to Matt, does it somehow relate to your concept on *data.array*?"},"comment":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/comments/201250492","html_url":"https://github.com/Rdatatable/data.table/issues/1418#issuecomment-201250492","issue_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1418","id":201250492,"user":{"login":"jangorecki","id":3627377,"avatar_url":"https://avatars.githubusercontent.com/u/3627377?v=3","gravatar_id":"","url":"https://api.github.com/users/jangorecki","html_url":"https://github.com/jangorecki","followers_url":"https://api.github.com/users/jangorecki/followers","following_url":"https://api.github.com/users/jangorecki/following{/other_user}","gists_url":"https://api.github.com/users/jangorecki/gists{/gist_id}","starred_url":"https://api.github.com/users/jangorecki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jangorecki/subscriptions","organizations_url":"https://api.github.com/users/jangorecki/orgs","repos_url":"https://api.github.com/users/jangorecki/repos","events_url":"https://api.github.com/users/jangorecki/events{/privacy}","received_events_url":"https://api.github.com/users/jangorecki/received_events","type":"User","site_admin":false},"created_at":"2016-03-25T11:57:49Z","updated_at":"2016-03-25T11:57:49Z","body":"Will hold on with that. I don't see a big problem with dcast'ing measures as post-process, but..\r\nLast dimension could be optionally kept in column, forming multiple measure, so it would be consistent with `as.data.table.matrix`."}}