I have a script to output graphic files via png()
the filename is based on a value(p) and the observation id ID(numerical value).
> summary(p)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.05328 0.10770 0.20830 0.31140 0.42360 0.99990
> summary(id)
Min. 1st Qu. Median Mean 3rd Qu. Max.
100000000 114100000 130400000 186100000 287300000 4513000
> str(p)
num [1:223] 0.175 0.1499 0.156 0.0636 0.1628 ...
> str(id)
int [1:223] 100037005 100270001 100270002 100801001 101910002 101910003 101910007 102510001 103630003 103630005 ...
so that
png(paste(p," - ", id,".png)
My goal is that the files in the output directory, when sorted by name, are in increasing p order, while the id is still in the filename.
I cant understand why but the sort order gets messed up, like in the attached screenshot.

Any ideas how I can get the output i need? A transformation of p is OK as long as it is easy to track back to the original value, and both p and id must be in the file name. I'm on Ubuntu 11.10.
Thanks a lot
You could try to make sure the p values are all the same length when converted to strings. Use sprintf:
pstring = sprintf("%010.8f",p)
will create a string with exactly 8 decimals, leading and trailing zeroes, and for values 0 to 1 will always be 10 characters long (zero, point, then eight decimals).
sprintf("%010.8f",runif(100))
should show you what it does.
Adjust the format according to your taste, simmer gently, serve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With