Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

dcast: check names? #27

Closed
MatthieuStigler opened this Issue · 1 comment

2 participants

@MatthieuStigler

Hi

When the variable that is getting casted into a new column has white spaces, columns of the new data frame with contain the same names, with the white spaces too.

aqm <- melt(airquality, id=c("Month", "Day"), na.rm=TRUE)
aqm$variable2<-factor(aqm$variable, levels=levels(aqm$variable),
labels=gsub("Ozone", "ozone with space", levels(aqm$variable)))
df<-dcast(aqm, day ~ variable2)
colnames(df)

This is in itself not a big problem, but makes some ways of indexing columns no more possible, or adds difficulties to handle with ggplot. The solution is very simple, involving only:
colnames(df) <- check.names(colnames(df))

it would be nice however if this could be directly made an argument of dcast() & co, making the code more compact and elegant!

Thanks!!

(this was discussed on manipulatr: http://groups.google.com/group/manipulatr/browse_thread/thread/60579a3cb89253b/b5738362f7c08a97?lnk=gst&q=stigler#b5738362f7c08a97)

@hadley
Owner

I now prefer to leave variables as is, since you can access with backquotes.

@hadley hadley closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.