[R] Problem with col
sarah.goslee at gmail.com
Mon Apr 20 19:05:44 CEST 2015
On Mon, Apr 20, 2015 at 12:56 PM, Sonia Amin <soniaamin5 at gmail.com> wrote:
> Sorry Sarah for my basic question: what does "a column was read as factor"
A factor is one of the basic types of data in R, and in statistics
generally, eg M/F or red/white/blue - a predetermined set of
categories that may or may not have an order.
More relevantly, if there's something wrong in your data, a stray
letter or quote mark for instance, that column is no longer numeric,
and R will read it as a factor by default, otherwise as character.
which is NOT the same as just typing data, will show you the classes
of your columns, among other things.
> When I type data , I obtain all the numeric values and the headears I added
If you just look at data directly, you'll see what look like numbers,
perhaps, but according to R one or more columns are not actually
numbers. That's why you need str(data).
Your problem looks like a lack of basic understanding of how R works.
Here are a couple of sources that might help you get started:
For more help, you should provide at least the output of str(data) to
the list, and ideally a reproducible example. Here are some
suggestions for creating a good reproducible example:
> 2015-04-20 18:40 GMT+02:00 Sarah Goslee <sarah.goslee at gmail.com>:
>> What is the problem? One or more of your columns was read as factor, as
>> would show you. To avoid this, you can add stringsAsFactors=FALSE to
>> the read.table command, but if you expect your data to be entirely
>> numeric then there's something wrong with it that you need to hunt
>> On Mon, Apr 20, 2015 at 12:33 PM, Sonia Amin <soniaamin5 at gmail.com> wrote:
>> > Dear All,
>> > I have written the following lines:
>> > data<-read.table("C:\\Users\\intel\\Documents\\SIIID\\datamultiplereg.txt",header
>> > = FALSE, sep = "")
>> > colnames(data)<-c("Consommation","Cylindre","Puissance","Poids")
>> > result.model1<-lm(Consommation~Cylindre+Puissance+Poids, data=data)
>> > summary(result.model1)
>> > I obtained the following message:
>> > Call:
>> > lm(formula = Consommation ~ Cylindre + Puissance + Poids, data = data)
>> > Residuals:
>> > Error in quantile.default(resid) : factors are not allowed
>> > In addition: warning message:
>> > In Ops.factor(r, 2) :
>> > ‘^’ This is not relevant for factors
>> > Where is the problem?
>> > Thank you in advance
>> Sarah Goslee
More information about the R-help