[R] Why isn't R recognising integers as numbers?

Ted Byers r.ted.byers at gmail.com
Mon Sep 22 03:56:48 CEST 2008


Thanks Jim,

Alas, it wasn't this.  Here is the output from both of your suggestions:

> refdata18 = read.csv("K:\\MerchantData\\RiskModel\\Capture.Week.18.csv",
> header = TRUE,na.strings="")
> str(refdata18)
'data.frame':   341 obs. of  1 variable:
 $ X0: int  0 0 0 0 0 0 0 0 0 0 ...
> scan("K:\\MerchantData\\RiskModel\\Capture.Week.18.csv", what=0L)
Read 342 items
  [1]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  0
 [26]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  0
 [51]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
0  0
 [76]  0  0  0  0  0  0  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 
1  1
[101]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 
1  1
[126]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 
1  1
[151]  1  1  1  1  1  1  1  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2 
2  2
[176]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  3  3  3  3  3  3  3  3 
3  3
[201]  3  3  3  3  3  3  3  3  3  3  3  3  3  4  4  4  4  4  4  4  4  4  4 
4  4
[226]  4  4  4  4  4  4  4  5  5  5  5  5  5  5  5  5  6  6  6  6  6  6  6 
6  6
[251]  6  6  6  6  6  6  6  6  6  6  6  6  6  6  7  7  7  7  7  7  7  7  7 
7  7
[276]  7  7  7  8  8  8  8  9  9  9  9  9  9  9  9  9 10 10 10 10 10 10 10
10 10
[301] 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12
12 12
[326] 12 12 12 18 18 18 18 18 18 18 18 18 18 18 18 18 18

Thanks anyway.

Ted
> 

jholtman wrote:
> 
> best guess is that they are not integers.  Do 'str' on your object and it
> probably says they are 'factors'.  This is probably due to some of your
> data
> being non-numeric.  Try using 'colClasses' on read.csv to specify what the
> column should contain.  Also try "scan" after skipping the first record if
> it is a header:
> 
>> scan("", what=0L)  # bad input after specifying integer
> 1: 1 2 3 4
> 5: 1 v
> 5:
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
> :
>   scan() expected 'an integer', got 'v'
>> scan("", what=0L)  # good input
> 1: 1
> 2: 2
> 3: 3
> 4:
> Read 3 items
> [1] 1 2 3
>>
> 
> On Sun, Sep 21, 2008 at 9:01 PM, Ted Byers <r.ted.byers at gmail.com> wrote:
> 
>>
>> I have a number of files containing anywhere from a few dozen to a few
>> thousand integers, one per record.
>>
>> The statement "refdata18 =
>> read.csv("K:\\MerchantData\\RiskModel\\Capture.Week.18.csv", header =
>> TRUE,na.strings="")" works fine, and if I type refdata18, I get the
>> integers
>> displayed, one value per record (along with a record number).  However,
>> when
>> I try " fitdistr(refdata18,"negative binomial")", or
>> hist.scott(refdata18,
>> prob = TRUE), I get an error:
>>
>> Error in fitdistr(refdata18, "negative binomial") :
>>  'x' must be a non-empty numeric vector
>> Or
>> Error in hist.default(x, nclass.scott(x), prob = prob, xlab = xlab, ...)
>> :
>>  'x' must be numeric
>>
>> How can it not recognise integers as numbers?
>>
>> Thanks
>>
>> Ted
>> --
>> View this message in context:
>> http://www.nabble.com/Why-isn%27t-R-recognising-integers-as-numbers--tp19600308p19600308.html
>> Sent from the R help mailing list archive at Nabble.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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem that you are trying to solve?
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Why-isn%27t-R-recognising-integers-as-numbers--tp19600308p19600695.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list