frederic.gosselin at cemagref.fr
2007-May-11 10:23 UTC
[Rd] changing the mode of a factor (PR#9675)
Full_Name: Fr?d?ric Gosselin
Version: 2.5 vs 2.4 and 2.2.1
OS: windows XP
Submission from: (NULL) (195.221.118.52)
#############
L3 <- LETTERS[1:3]
(d <- data.frame(cbind(x=1, y=1:10), fac=as.factor(sample(L3, 10,
repl=TRUE))))
mode(d[,3])<-"numeric"
###############
when trying to change the mode of a column in a data.frame that is a factor to
numeric(cf. preceding code), the following error occurs (in French) in R 2.5:
Erreur dans `storage.mode<-`(`*tmp*`, value = "double") :
le mode de stockage d'un objet "factor" ne peut ?tre
modifi?
The same thing works fine in R2.4 and 2.2.1.
It does not seem to correspond to new things announced in the NEWS file for the
2.5 version...
ripley at stats.ox.ac.uk
2007-May-14 11:37 UTC
[Rd] changing the mode of a factor (PR#9675)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--27464147-942662499-1179141762=:28940
Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-1; FORMAT=flowed
Content-Transfer-Encoding: 8BIT
Content-ID: <Pine.LNX.4.64.0705141227241.28940 at gannet.stats.ox.ac.uk>
How about the following NEWS item (a bug fix)
o Assigning class "factor" to an object now requires it has
integer (and not say double) codes.
? (Changing the mode to double amounted to creating a new double vector
and then assigning the attributes of the old object including the class.
We gave a more specific error message in this case in an attempt to be
helpful ....)
>From ?factor
'factor' returns an object of class '"factor"'
which has a set of
integer codes the length of 'x' with a
'"levels"' attribute of
mode 'character'. If 'ordered' is true (or
'ordered' is used) the
result has class 'c("ordered", "factor")'.
So a factor necessarily has integer codes. That you were able to change
the mode in earlier versions of R was a bug that has been fixed.
You may well want one of the answers to FAQ 7.10.
Please take note of the 'BUGS' section in the FAQ and the posting guide:
three incorrect bug items in one day is unhelpful.
On Fri, 11 May 2007, frederic.gosselin at cemagref.fr wrote:
> Full_Name: Fr?d?ric Gosselin
> Version: 2.5 vs 2.4 and 2.2.1
> OS: windows XP
> Submission from: (NULL) (195.221.118.52)
>
>
> #############
> L3 <- LETTERS[1:3]
> (d <- data.frame(cbind(x=1, y=1:10), fac=as.factor(sample(L3, 10,
> repl=TRUE))))
> mode(d[,3])<-"numeric"
> ###############
>
> when trying to change the mode of a column in a data.frame that is a factor
to
> numeric(cf. preceding code), the following error occurs (in French) in R
2.5:
>
> Erreur dans `storage.mode<-`(`*tmp*`, value = "double") :
> le mode de stockage d'un objet "factor" ne peut ?tre
modifi?
>
> The same thing works fine in R2.4 and 2.2.1.
>
> It does not seem to correspond to new things announced in the NEWS file for
the
> 2.5 version...
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
--27464147-942662499-1179141762=:28940--
Possibly Parallel Threads
- Newbie Questions
- different results across versions for glmer/lmer with the quasi-poisson or quasi-binomial families: the lattest version might not be accurate...
- [R-sig-Geo] plot() and Jpeg() increase font size and resolution
- plot() and Jpeg() increase font size and resolution
- File Encoding Warnings during package installs