Q:

How to keep the value length in output file after division operation in R?

I need to format a file. I have one column need to division by 1000000.
After the division operation, the new column will output.
I check the output file. Some values after division operation, the end of zero will be remove.
For example input 212740 212740/1000000=0.212740, the output is 0.21274. But I need my value is 0.212740.
How should I do to keep the end of zero in the value?
I am think maybe I can edit my write.table function?
Any suggestions for this?
my code:
A$cM=A[,c(4)]/1000000
write.table(file,'BigXP5.txt', sep=' ', quote=F, row.names=F, col.names=F);

Thanks
Victor

A:

You can use
format(212740/1000000,nsmall=6) that give you 0.212740 output
and for your dataset use
A$cM=format(A[,c(4)]/1000000,nsmall=6)
for more cases see Formatting Decimal places in R

