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!
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)