I want to use stack to a data frame and keep duplicate columnnames from a original data frame.
a1<-data.frame(1:10,11:20,21:30)
colnames(a1)<-c('a','b','a')
a2<-stack(a1)
Above adds ‘a.1’ for duplicate column names for ‘a’ in a2. I want to keep it as ‘a’. Is there any option for this in stack?
Alternatively I tried to replace all ‘a1.1’ using a loop. I wasn’t successful in the large table with many duplicate names. Is there any better example for replacing the pattern (strings) in r rows?
Finally, I am here asking my first question in forum. Thanks for your help.
By looking at the code for
stackby:As you see the
...parameter is not passed to thedata.framecreation. You could modify this function by creating saystack2as follows:Note: Don’t pass
stringsAsFactors = .argument to thisstack2function as its already passed. Probably that’s why they don’t pass the...argument?