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)
labels=gsub("Ozone", "ozone with space", levels(aqm$variable)))
df<-dcast(aqm, day ~ variable2)
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!
(this was discussed on manipulatr: http://groups.google.com/group/manipulatr/browse_thread/thread/60579a3cb89253b/b5738362f7c08a97?lnk=gst&q=stigler#b5738362f7c08a97)
I now prefer to leave variables as is, since you can access with backquotes.