Hi all,
I stumbled across the following, in my opinion surprising, behaviour of
read.table:
> data <- read.table(stdin(), sep=",")
0: 1, 2, 3 # Some comment
1:
> sapply(data, class)
V1 V2 V3
"integer" "integer" "numeric"
I was surprised to find that V3 has class "numeric" despite its
apparent
integer value. I took a look at type.convert (which is called by
read.data to determine column classes) for explanation (I quote from the
man page):
"Vectors containing optional whitespace followed by decimal
constants representable as R integers [...] are converted to integer.
Other vectors containing optional whitespace followed by other decimal
or hexadecimal constants [...] are converted to numeric."
Obviously the trailing whitespace between '3' and the comment sign
'#'
is treated as "other decimal or hexadecimal constant" while the
leading
whitespace before "2" is stripped. Actually, leaving just the trailing
space after '3' without the comment gives the same result. Is there any
reason for this behaviour?
Best regards,
Andreas
--
Andreas Borg
Medizinische Informatik
UNIVERSIT?TSMEDIZIN
der Johannes Gutenberg-Universit?t
Institut f?r Medizinische Biometrie, Epidemiologie und Informatik
Obere Zahlbacher Stra?e 69, 55131 Mainz
www.imbei.uni-mainz.de
Telefon +49 (0) 6131 175062
E-Mail: borg at imbei.uni-mainz.de
Diese E-Mail enth?lt vertrauliche und/oder rechtlich gesch?tzte Informationen.
Wenn Sie nicht der
richtige Adressat sind oder diese E-Mail irrt?mlich erhalten haben, informieren
Sie bitte sofort den
Absender und l?schen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte
Weitergabe
dieser Mail und der darin enthaltenen Informationen ist nicht gestattet.