David Kane <David Kane
2002-Jul-23 13:33 UTC
[R] colClasses = "logical" produces all FALSE when input is 1/0
It seems to me that colClasses = "logical" in read.table produces incorrect results when the input file has `1' and `0' in it. Although, it is perhaps just as likely that I am misunderstanding the documentation. Here is a simple example:> file.show("test.txt")x 1 0 1> read.table("test.txt", header = TRUE)x 1 1 2 0 3 1 This result is fine.> read.table("test.txt", header = TRUE, colClasses = "character")x 1 1 2 0 3 1 This one also. However, I think that this result is wrong:> readtable("test.txt", header = TRUE, colClasses = "logical")x 1 FALSE 2 FALSE 3 FALSE I would have expected: x 1 TRUE 2 FALSE 3 TRUE Is there a way to get what I expected? Alas, I can't quite make out what read.table is doing in this context.> R.version_ platform sparc-sun-solaris2.6 arch sparc os solaris2.6 system sparc, solaris2.6 status major 1 minor 5.1 year 2002 month 06 day 17 language R>Any suggestions would be much appreciated. Regards, Dave Kane -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ripley@stats.ox.ac.uk
2002-Jul-23 13:43 UTC
[R] colClasses = "logical" produces all FALSE when input is 1/0
On Tue, 23 Jul 2002, David Kane <David Kane wrote:> It seems to me that colClasses = "logical" in read.table produces incorrect results when > the input file has `1' and `0' in it. Although, it is perhaps just as likely > that I am misunderstanding the documentation.[ ... ]> This one also. However, I think that this result is wrong: > > > readtable("test.txt", header = TRUE, colClasses = "logical") > x > 1 FALSE > 2 FALSE > 3 FALSEWhy? 0 and 1 are not valid values for a logical variable.> I would have expected: > > x > 1 TRUE > 2 FALSE > 3 TRUE > > Is there a way to get what I expected?Read as it as character or integer and convert later.> Alas, I can't quite make out what read.table is doing in this context.It is using scan():> scan(what=logical(0))1: 0 1 0 4: Read 3 items [1] FALSE FALSE FALSE Anything other than T or TRUE is taken as false. Perhaps it would have confused you less if we had thrown an error. -- Brian D. Ripley, ripley at 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-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._