{"action":"closed","issue":{"url":"https://api.github.com/repos/hadley/dplyr/issues/1078","labels_url":"https://api.github.com/repos/hadley/dplyr/issues/1078/labels{/name}","comments_url":"https://api.github.com/repos/hadley/dplyr/issues/1078/comments","events_url":"https://api.github.com/repos/hadley/dplyr/issues/1078/events","html_url":"https://github.com/hadley/dplyr/issues/1078","id":68351464,"number":1078,"title":"enable replacement of values","user":{"login":"stefanfritsch","id":7372706,"avatar_url":"https://avatars.githubusercontent.com/u/7372706?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanfritsch","html_url":"https://github.com/stefanfritsch","followers_url":"https://api.github.com/users/stefanfritsch/followers","following_url":"https://api.github.com/users/stefanfritsch/following{/other_user}","gists_url":"https://api.github.com/users/stefanfritsch/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanfritsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanfritsch/subscriptions","organizations_url":"https://api.github.com/users/stefanfritsch/orgs","repos_url":"https://api.github.com/users/stefanfritsch/repos","events_url":"https://api.github.com/users/stefanfritsch/events{/privacy}","received_events_url":"https://api.github.com/users/stefanfritsch/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-14T12:06:41Z","updated_at":"2015-05-19T15:35:35Z","closed_at":"2015-05-19T15:35:35Z","body":"Hi,\r\n\r\ncurrently dplyr is not really convenient if you want to replace specific values in a data.frame based on a condition on the obs. Let's say you want to set variable b to -a if variable a is <0.\r\n\r\n\r\n```R\r\ndt[a<0, b := -a]\r\n```\r\n\r\nAFAIK there is no easy way in dplyr. Using `ifelse` in mutate works but becomes really unwieldy if there is more than one column, e.g.\r\n\r\n```R\r\ndt[a<0, \r\n   `:=`(b=-a, \r\n        d=sqrt(-a+d))]\r\n```\r\n\r\nThis would be helped immensely by a \"where\" (I know, that's not a verb; you were brave enough to change override in MASS, so perhaps \"subset\"?) analogue to group_by, that instead limits effects to a subset of the table.\r\n\r\n```R\r\ndt %>%\r\n  subset(a<0) %>%\r\n  mutate(b=-a,\r\n         d=sqrt(-a+d)) %>%\r\n  unsubset\r\n```\r\n\r\nIs that a realistic possibility or is it an absolute no-go? :)\r\n\r\nCiao,\r\nStefan"}}