The following command, temp <- read.table("c:/rfr/r/test.txt") reads the text file "test.txt", which contains the following lines: 21437 21438 21419-2 21420-2 21421-2 21422-2 and produces the following result:> tempV1 1 21437+0i 2 21438+0i 3 0+0i 4 0+0i 5 0+0i 6 0+0i>These "numbers" are actually sample ID's, and I expected the presence of the hyphen would cause temp to be character or a factor, but it ends up as complex numbers. System info: platform i386-pc-mingw32 arch x86 os Win32 system x86, Win32 status major 1 minor 4.1 year 2002 month 01 day 30 language R>Following is a diagnosis of the problem by one of my colleagues:> From: Huntsinger, Reid > Sent: Monday, April 22, 2002 5:15 PM > To: Raubertas, Richard > Subject: RE: R problem > > [ ... ] This happens > because of the attempt to convert. The function type.convert > is called on columns with unspecified types; this tries to > convert to "logical, integer, numeric or complex" in that > order (first one that is successful wins). You have some ids > like 21428-2 which type.convert doesn't like as numeric but > will treat as complex. This in turn is due to R's hand-rolled > "strtoc" function, which returns 0+0i for something it > doesn't like. This is a valid value, so the conversion > "works", and all values are converted this way... > > You or I should probably alert the R people. That's not very > good behavior.------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. ============================================================================= -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
richard_raubertas@merck.com writes:> > From: Huntsinger, Reid > > Sent: Monday, April 22, 2002 5:15 PM > > To: Raubertas, Richard > > Subject: RE: R problem > > > > [ ... ] This happens > > because of the attempt to convert. The function type.convert > > is called on columns with unspecified types; this tries to > > convert to "logical, integer, numeric or complex" in that > > order (first one that is successful wins). You have some ids > > like 21428-2 which type.convert doesn't like as numeric but > > will treat as complex. This in turn is due to R's hand-rolled > > "strtoc" function, which returns 0+0i for something it > > doesn't like. This is a valid value, so the conversion > > "works", and all values are converted this way... > > > > You or I should probably alert the R people. That's not very > > good behavior.Right, but not something we can fix for 1.5.0. Another version of the same effect is> scan(what=0+0i)1: 21419-2 2: Read 1 items [1] 0+0i A workaround would be to use the colClasses argument, or as.is. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 23 Apr 2002, Peter Dalgaard BSA wrote:> richard_raubertas@merck.com writes: > > > > From: Huntsinger, Reid > > > Sent: Monday, April 22, 2002 5:15 PM > > > To: Raubertas, Richard > > > Subject: RE: R problem > > > > > > [ ... ] This happens > > > because of the attempt to convert. The function type.convert > > > is called on columns with unspecified types; this tries to > > > convert to "logical, integer, numeric or complex" in that > > > order (first one that is successful wins). You have some ids > > > like 21428-2 which type.convert doesn't like as numeric but > > > will treat as complex. This in turn is due to R's hand-rolled > > > "strtoc" function, which returns 0+0i for something it > > > doesn't like. This is a valid value, so the conversion > > > "works", and all values are converted this way... > > > > > > You or I should probably alert the R people. That's not very > > > good behavior. > > Right, but not something we can fix for 1.5.0. Another version of the > same effect is > > > scan(what=0+0i) > 1: 21419-2 > 2: Read 1 items > [1] 0+0i > > A workaround would be to use the colClasses argument, or as.is.Actually it is already fixed: it was a very simple fix. The problem was being detected: it was just not being reported. As this was just a case of what is done in an error condition (it can't affect any valid input) I thought it safe to fix a week before release. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._