Matthew Keller
2011-May-29 23:28 UTC
[R] why does scan(gzfile("file"), what='integer') import data as mode "character" ?
Hi all, My code: x <- scan(gzfile("file"),what='integer') x is imported, but as mode "character" rather than "integer". I know I can do as.integer() when importing, but am still trying to figure out why the above occurs. When I do summary(as.integer(x)), there are no NAs introduced by coercion, so the vector really is all integer. Also, is the above code the fastest for importing a very long zipped data, with 132 million rows and 1 column? Thanks in advance, Matt -- Matthew C Keller Asst. Professor of Psychology University of Colorado at Boulder www.matthewckeller.com
William Dunlap
2011-May-29 23:41 UTC
[R] why does scan(gzfile("file"), what='integer') import data as mode "character" ?
Try giving what an example of an integer instead of the character string "integer". E.g., what = 0L or what = integer(0) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Matthew Keller > Sent: Sunday, May 29, 2011 4:28 PM > To: r help > Subject: [R] why does scan(gzfile("file"), what='integer') > import data as mode "character" ? > > Hi all, > > My code: > > x <- scan(gzfile("file"),what='integer') > > x is imported, but as mode "character" rather than "integer". I know I > can do as.integer() when importing, but am still trying to figure out > why the above occurs. When I do > summary(as.integer(x)), there are no NAs introduced by coercion, so > the vector really is all integer. > > Also, is the above code the fastest for importing a very long zipped > data, with 132 million rows and 1 column? > > Thanks in advance, > > Matt > > > -- > Matthew C Keller > Asst. Professor of Psychology > University of Colorado at Boulder > www.matthewckeller.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >