An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110312/e39ecdc8/attachment.pl>
Column order in stacking/unstacking
4 messages · Dennis Murphy, Peter Ehlers, Matthew Carroll
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110312/a5062207/attachment.pl>
On 2011-03-12 02:01, Dennis Murphy wrote:
Hi:
It would help if you named your variables such that alphanumeric ordering
doesn't disturb your variable ordering. Having been burned by this a few
times, I've learned the basics of sprintf() :) Here's your example
revisited, along with an alternative stacking/unstacking display with
package reshape.
library(reshape)
vnames<- paste('X', sprintf('%02d', c(1, 2, 10)), sep = '')
vnames
[1] "X01" "X02" "X10"
<snip>
You can do this a bit more simply with sprintf:
vnames <- sprintf("%s%02d", "X", c(1, 2, 10))
Peter Ehlers
Dear Dennis and Peter,
Thank you for the suggestions - they work very well with my example data.
I *think* I've got it up and running using my real data (with 2000 columns)
too, with:
sprintf("%s%04d", "X", c(1:2000))
then the stacking/unstacking operations.
Thanks again for the help
Best wishes,
Matthew
-----Original Message-----
From: Peter Ehlers [mailto:ehlers at ucalgary.ca]
Sent: 12 March 2011 11:09 AM
To: Dennis Murphy
Cc: Matthew Carroll; r-help at r-project.org
Subject: Re: [R] Column order in stacking/unstacking
On 2011-03-12 02:01, Dennis Murphy wrote:
Hi:
It would help if you named your variables such that alphanumeric ordering
doesn't disturb your variable ordering. Having been burned by this a few
times, I've learned the basics of sprintf() :) Here's your example
revisited, along with an alternative stacking/unstacking display with
package reshape.
library(reshape)
vnames<- paste('X', sprintf('%02d', c(1, 2, 10)), sep = '')
vnames
[1] "X01" "X02" "X10"
<snip>
You can do this a bit more simply with sprintf:
vnames <- sprintf("%s%02d", "X", c(1, 2, 10))
Peter Ehlers