[R] Why isn't R recognising integers as numbers?
Ted Byers
r.ted.byers at gmail.com
Mon Sep 22 04:09:29 CEST 2008
Thanks Marc,
That was it.
For the last 30 years, I'd write my own code, in FORTRAN, C++, or even Java,
to do whatever statistical analysis I needed. When at the office, sometimes
I could use SAS, but that hasn't been an option for me in years.
This is the first time I have had to load real data into R (instead of
generating random data to use while playing with some of the stats
functions, or manually typing dummy data).
I take it, then, that the result of loading data is a data frame, and not
just a matrix or array. Using something like "refdata18[, 1]" feels rather
alien, but I'm sure I'll quickly get used to it. I'd seen it before in the
R docs, but it didn't register that I had to use it to get the functions of
most interest to me to recognise my data as a vector of numbers, given I'd
provided only a vector of integers as input.
Thanks
Ted
Marc Schwartz wrote:
>
> on 09/21/2008 08:01 PM Ted Byers 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
>
> 'refdata18' is a data frame and the two functions are expecting a
> numeric vector.
>
> If you use:
>
> fitdistr(refdata18[, 1], "negative binomial")
>
> or
>
> hist(refdata18[, 1])
>
> you should get a suitable result, presuming that the first column in the
> data frame is a numeric vector.
>
> Use:
>
> str(refdata18)
>
> to get a sense for the structure of the data frame, including the column
> names, which you could then use, instead of the above index based syntax.
>
> HTH,
>
> Marc Schwartz
>
> ______________________________________________
> 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--tp19600308p19600803.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list