Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutate/summarise bugs #24

Closed
hadley opened this issue Jun 12, 2013 · 0 comments
Closed

Mutate/summarise bugs #24

hadley opened this issue Jun 12, 2013 · 0 comments

Comments

@hadley
Copy link
Member

hadley commented Jun 12, 2013

From Dave Cooper:

# mutate and summarize bugs.R

rm(list = ls())

require(plyr)
require(ggplot2)

d = diamonds

#########################
# MUTATE BUG
# this works
e = mutate(d,
  cut2 = as.character(cut) )
e = mutate(e,
  cut2 = ifelse(cut2 == 'Fair', '*Fairest*', cut2))
plyr::count(e, ~cut+cut2)

# this fails
e = mutate(d,
  cut2 = as.character(cut),
  cut2 = ifelse(cut2 == 'Fair', '*Fairest*', cut2))
plyr::count(e, ~cut+cut2)

# but this works!
e = mutate(d,
  cut2 = as.character(cut),
  cut3 = ifelse(cut2 == 'Fair', '*Fairest*', cut2))
plyr::count(e, ~cut+cut2+cut3)

#########################
# SAME PROBLEM, BUT WITH SUMMARIZE
# this works
e = summarize(d,
  cut2 = as.character(cut) )
e = summarize(e,
  cut2 = ifelse(cut2 == 'Fair', '*Fairest*', cut2))
count(e, ~cut2)

# this fails
e = summarize(d,
  cut2 = as.character(cut),
  cut2 = ifelse(cut2 == 'Fair', '*Fairest*', cut2))
count(e, ~cut2)

# but this works!
e = summarize(d,
  cut2 = as.character(cut),
  cut3 = ifelse(cut2 == 'Fair', '*Fairest*', cut2))
count(e, ~cut2+cut3)


#########################
# MUTATE with REVALUE
# this works
e = mutate(d,
 cut2 = revalue(cut, c(Fair = '*Fairest*')) )
e = mutate(e,
 cut2 = revalue(cut2, c('*Fairest*' = '*Fairest of All*')) )
count(e, ~cut+cut2)

# this fails
e = mutate(d,
 cut2 = revalue(cut, c(Good = '*Fairest*')),
 cut2 = revalue(cut2, c('*Fairest*' = '*Fairest of All*')) )
count(e, ~cut+cut2)

# but this works!
e = mutate(d,
 cut2 = revalue(cut, c(Good = '*Fairest*')),
 cut3 = revalue(cut2, c('*Fairest*' = '*Fairest of All*')) )
count(e, ~cut+cut2+cut3)
@hadley hadley closed this as completed in cfae81a Aug 12, 2013
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant