{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/tidyr/issues/94","labels_url":"https://api.github.com/repos/hadley/tidyr/issues/94/labels{/name}","comments_url":"https://api.github.com/repos/hadley/tidyr/issues/94/comments","events_url":"https://api.github.com/repos/hadley/tidyr/issues/94/events","html_url":"https://github.com/hadley/tidyr/issues/94","id":95441671,"number":94,"title":"pivot pairs of key-value variables using tidyr:spread()","user":{"login":"ronencozen","id":7824971,"avatar_url":"https://avatars.githubusercontent.com/u/7824971?v=3","gravatar_id":"","url":"https://api.github.com/users/ronencozen","html_url":"https://github.com/ronencozen","followers_url":"https://api.github.com/users/ronencozen/followers","following_url":"https://api.github.com/users/ronencozen/following{/other_user}","gists_url":"https://api.github.com/users/ronencozen/gists{/gist_id}","starred_url":"https://api.github.com/users/ronencozen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronencozen/subscriptions","organizations_url":"https://api.github.com/users/ronencozen/orgs","repos_url":"https://api.github.com/users/ronencozen/repos","events_url":"https://api.github.com/users/ronencozen/events{/privacy}","received_events_url":"https://api.github.com/users/ronencozen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-07-16T14:10:32Z","updated_at":"2015-07-30T15:58:24Z","closed_at":null,"body":"I am trying to pivot pairs of key-value variables using tidyr:spread() .\r\n\r\nid <- c(0,1,2,3,4,5,6,7,8,9)\r\nHi, \r\nkey1 <- c(\"a\", \"a\", \"b\", \"b\", \"c\",\"a\", \"a\", \"b\", \"b\", \"c\")\r\nval1 <- c(1,2,3,1,2,3,1,2,3,1)\r\nkey2 <- c(\"d\",NA,NA,NA,\"e\",\"d\",\"d\",NA,\"b\",NA)\r\nval2 <- c(1,NA,NA,NA,2,3,NA,NA,3,NA)\r\nkey3 <- c(\"x\",NA,NA,NA,\"e\",\"d\",NA,NA,NA,NA)\r\nval3 <- c(0,NA,NA,NA,NA,3,1,NA,NA,NA)\r\ndf = data.frame(id, key1, val1, key2, val2, key3, val3) \r\nlibrary(tidyr)\r\nc1 <- spread(df, key1, val1, fill = 0, convert = FALSE)\r\nc2 <- spread(c1, key2, val2, fill = 0, convert = FALSE)\r\nc3 <- spread(c2, key3, val3, fill = 0, convert = FALSE) \r\n\r\nwhile running the spread(), i get the following error:\r\n\r\nError in [.data.frame(data, setdiff(names(data), c(key_col, value_col))) : undefined columns selected\r\n\r\nIt makes me think that the problem is incorrect NA handling ?\r\n\r\non the same token, is there a more syntax efficient way to spread multiple pair of key-value variables?\r\n\r\nThank you!"},"comment":{"url":"https://api.github.com/repos/hadley/tidyr/issues/comments/126380419","html_url":"https://github.com/hadley/tidyr/issues/94#issuecomment-126380419","issue_url":"https://api.github.com/repos/hadley/tidyr/issues/94","id":126380419,"user":{"login":"hadley","id":4196,"avatar_url":"https://avatars.githubusercontent.com/u/4196?v=3","gravatar_id":"","url":"https://api.github.com/users/hadley","html_url":"https://github.com/hadley","followers_url":"https://api.github.com/users/hadley/followers","following_url":"https://api.github.com/users/hadley/following{/other_user}","gists_url":"https://api.github.com/users/hadley/gists{/gist_id}","starred_url":"https://api.github.com/users/hadley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadley/subscriptions","organizations_url":"https://api.github.com/users/hadley/orgs","repos_url":"https://api.github.com/users/hadley/repos","events_url":"https://api.github.com/users/hadley/events{/privacy}","received_events_url":"https://api.github.com/users/hadley/received_events","type":"User","site_admin":false},"created_at":"2015-07-30T15:58:24Z","updated_at":"2015-07-30T15:58:24Z","body":"@ronencozen But why sum? There are lots of other ways you could aggregate multiple values.  The goal of each function in tidyr is to do one thing well, so I think it would be a bad idea to all do aggregation in `spread()`."}}