1

I am trying to use the write.table() function in R to write an output. It has 3 columns, first has numbers, the second has a color indicator (#000000) and the third one has a number again. Simple enough right?

Well, when I run my script step by step, the output is the desired one, something like this:

Tip ID Color Track Cluster ID

13298267 #FF0000 1

But when I try to do it through command line, with exactly the same number and the same arguments, I get something like this:

13298267 #FF0000 156

I tried changing the encoding and nothing happened, I tried changing the third column as a number instead of an integer. Nothing

Does someone have any idea of what might be happening?

Community
  • 1
  • 1
MLMH
  • 141
  • 8
  • [Reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) is always welcome. – zero323 Jun 04 '15 at 09:30
  • Check the class of the Cluster ID (with str() ) - maybe its a factor and not numeric? – MarkeD Jun 04 '15 at 09:30
  • I am not really sure about how to do a reproducible example in this case... – MLMH Jun 04 '15 at 09:31
  • Thanks @MarkeD, I checked before but not after doing the matrix, and you were right, it was converted to factor. – MLMH Jun 04 '15 at 09:42

1 Answers1

1

This often happens if the class of the object is a factor, and not the expected numeric. This is because the print() functions for factors and numerics will both output an (often different) number at a casual glance.

Best way to avoid it is to always check using str() what classes your objects are.

MarkeD
  • 2,500
  • 2
  • 21
  • 35