Is it possible to change the default separator when cast (dcast) assigns new column headers?
I am converting a file from long to wide, and I get the following headers:
value_1, value_2, value_3,...
In reshape you can assign the "sep" parameter (sep="") and the column headers output like I want them to:
value1, value2, value3,...
However, reshape takes minutes for my data frame with over 200,000 rows, whereas dcast takes seconds. dcast also outputs the columns in the order I want, where reshape does not. Is there any easy way to change the output with dcast, or do I need to change the column headers manually?
For example:
example <- data.frame(id=rep(c(1,2,3,4),4),index=c(rep(1,4),rep(2,4),rep(1,4),rep(2,4)),variable=c(rep("resp",8),rep("conc",8)),value=rnorm(16,5,1))
dcast(example,id~variable+index)
The example gives the column headers:
conc_1, conc_2, resp_1, resp_2
I want the column headers to read:
conc1, conc2, resp1, resp2
I have tried:
dcast(example,id~variable+index,sep="")
dcast appears to ignore sep entirely, because giving a symbol does not change the output either.