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

Setting value variable in cast does not if "value" column already exists #1

Closed
hadley opened this issue Jan 28, 2010 · 3 comments
Closed

Comments

@hadley
Copy link
Owner

hadley commented Jan 28, 2010

df <- data.frame(
  id1 = rep(letters[1:2],2), 
  id2 = rep(LETTERS [1:2],each=2), var1=1:4)

df.m <- melt(df)
df.m$value2 <- runif(4)
cast(df.m, id1~id2, value="value")
cast(df.m, id1~id2, value="value2")
@hadley
Copy link
Owner Author

hadley commented Jan 28, 2010

From Baptiste:

s far as I can see the problem appears when the data.frame contains a
variable "value" (e.g. as a result of melt()). In this case we end up
with two value variables after the following line in cast,

if (any(names(data) == value))
  names(data)[names(data) == value] <- "value"
browser() # data has two value variables

@baptiste
Copy link

something like this might be good enough for a quick fix,

if (any(names(data) == value) & value != "value") {
names(data)[names(data) == "value"] <- ".value"
names(data)[names(data) == value] <- "value"
}

@hadley
Copy link
Owner Author

hadley commented Dec 28, 2010

I'm closing this because it's fixed in reshape2

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants