{"action":"opened","issue":{"url":"https://api.github.com/repos/HenrikBengtsson/Wishlist-for-R/issues/5","labels_url":"https://api.github.com/repos/HenrikBengtsson/Wishlist-for-R/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/HenrikBengtsson/Wishlist-for-R/issues/5/comments","events_url":"https://api.github.com/repos/HenrikBengtsson/Wishlist-for-R/issues/5/events","html_url":"https://github.com/HenrikBengtsson/Wishlist-for-R/issues/5","id":124221295,"number":5,"title":"Preserve element names in multi-dimensional subsetting","user":{"login":"HenrikBengtsson","id":1616850,"avatar_url":"https://avatars.githubusercontent.com/u/1616850?v=3","gravatar_id":"","url":"https://api.github.com/users/HenrikBengtsson","html_url":"https://github.com/HenrikBengtsson","followers_url":"https://api.github.com/users/HenrikBengtsson/followers","following_url":"https://api.github.com/users/HenrikBengtsson/following{/other_user}","gists_url":"https://api.github.com/users/HenrikBengtsson/gists{/gist_id}","starred_url":"https://api.github.com/users/HenrikBengtsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HenrikBengtsson/subscriptions","organizations_url":"https://api.github.com/users/HenrikBengtsson/orgs","repos_url":"https://api.github.com/users/HenrikBengtsson/repos","events_url":"https://api.github.com/users/HenrikBengtsson/events{/privacy}","received_events_url":"https://api.github.com/users/HenrikBengtsson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/HenrikBengtsson/Wishlist-for-R/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-29T14:55:00Z","updated_at":"2015-12-29T14:55:00Z","closed_at":null,"body":"# Background\r\nVectors in can have dimensions and corresponding names, cf. `dim()` and `dimnames()`.  They can concurrently have element names, cf. `names()`.  For instance,\r\n```r\r\n> x <- matrix(1:6, nrow=2)\r\n> rownames(x) <- c(\"A\", \"B\")\r\n> colnames(x) <- c(\"X\", \"Y\", \"Z\")\r\n> names(x) <- letters[1:6]\r\n> x\r\n  X Y Z\r\nA 1 3 5\r\nB 2 4 6\r\nattr(,\"names\")\r\n[1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\"\r\n```\r\nThis allows us to access elements both by dimensional names as by element names, e.g.\r\n```r\r\n> x[3]\r\nc\r\n3\r\n> x[\"c\"]\r\nc\r\n3\r\n> x[1,2]\r\n[1] 3\r\n> x[\"A\",\"Y\"]\r\n[1] 3\r\n```\r\n\r\n# Problem\r\nWhen subsetting by dimensions, we loose the element names, e.g.\r\n```r\r\n> y <- x[,2:3]\r\n> y\r\n  Y Z\r\nA 3 5\r\nB 4 6\r\n> names(y)\r\nNULL\r\n```\r\n\r\n# Wish\r\nPreserve element names also when subsetting by dimensions, e.g.\r\n```r\r\n> y\r\n  Y Z\r\nA 3 5\r\nB 4 6\r\nattr(,\"names\")\r\n[1] \"c\" \"d\" \"e\" \"f\"\r\n> y[1]\r\nc\r\n3\r\n> y[\"c\"]\r\nc\r\n3\r\n```\r\n"}}