given what ?identical says, i find the following odd: x = 1:10 y = 1:10 all.equal(x,y) [1] TRUE identical(x,y) [1] TRUE y[11] = 11 y = y[1:10] all.equal(x,y) [1] TRUE identical(x,y) [1] FALSE y [1] 1 2 3 4 5 6 7 8 9 10 length(y) [1] 10 looks like a bug. platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 7.0 year 2008 month 04 day 22 svn rev 45424 language R version.string R version 2.7.0 (2008-04-22) vQ -- ------------------------------------------------------------------------------- Wacek Kusnierczyk, MD PhD Email: waku at idi.ntnu.no Phone: +47 73591875, +47 72574609 Department of Computer and Information Science (IDI) Faculty of Information Technology, Mathematics and Electrical Engineering (IME) Norwegian University of Science and Technology (NTNU) Sem Saelands vei 7, 7491 Trondheim, Norway Room itv303 Bioinformatics & Gene Regulation Group Department of Cancer Research and Molecular Medicine (IKM) Faculty of Medicine (DMF) Norwegian University of Science and Technology (NTNU) Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway Room 231.05.060
the str function shows that x is an int and y is a num so it's probably not a bug. or maybe the conversion to num is but probably not the identical. x = 1:10 y = 1:10 all.equal(x,y) identical(x,y) y[11] = 11 y = y[1:10] all.equal(x,y) identical(x,y) print(str(y)) print(str(x)) On Sun, Oct 26, 2008 at 5:39 PM, Wacek Kusnierczyk wrote:> given what ?identical says, i find the following odd: > > x = 1:10 > y = 1:10 > > all.equal(x,y) > [1] TRUE > identical(x,y) > [1] TRUE > > y[11] = 11 > y = y[1:10] > > all.equal(x,y) > [1] TRUE > identical(x,y) > [1] FALSE > > y > [1] 1 2 3 4 5 6 7 8 9 10 > length(y) > [1] 10 > > > looks like a bug. > > platform i686-pc-linux-gnu arch i686 > os linux-gnu system i686, > linux-gnu status major > 2 minor 7.0 > year 2008 month 04 > day 22 svn rev 45424 > language R version.string R version > 2.7.0 (2008-04-22) > > > vQ > > -- > > ------------------------------------------------------------------------------- > Wacek Kusnierczyk, MD PhD > > Email: waku at idi.ntnu.no > Phone: +47 73591875, +47 72574609 > > Department of Computer and Information Science (IDI) > Faculty of Information Technology, Mathematics and Electrical > Engineering (IME) > Norwegian University of Science and Technology (NTNU) > Sem Saelands vei 7, 7491 Trondheim, Norway > Room itv303 > > Bioinformatics & Gene Regulation Group > Department of Cancer Research and Molecular Medicine (IKM) > Faculty of Medicine (DMF) > Norwegian University of Science and Technology (NTNU) > Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway > Room 231.05.060 > > ______________________________________________ > 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.
If you want them to be identical, then you have to explicitly assign an integer to the vector so that conversion is not done:> x = 1:10 > y = 1:10 > > all.equal(x,y)[1] TRUE> > identical(x,y)[1] TRUE> > > y[11] = 11L > y = y[1:10] > > all.equal(x,y)[1] TRUE> > identical(x,y)[1] TRUE>On Sun, Oct 26, 2008 at 6:39 PM, Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:> given what ?identical says, i find the following odd: > > x = 1:10 > y = 1:10 > > all.equal(x,y) > [1] TRUE > identical(x,y) > [1] TRUE > > y[11] = 11 > y = y[1:10] > > all.equal(x,y) > [1] TRUE > identical(x,y) > [1] FALSE > > y > [1] 1 2 3 4 5 6 7 8 9 10 > length(y) > [1] 10 > > > looks like a bug. > > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 2 > minor 7.0 > year 2008 > month 04 > day 22 > svn rev 45424 > language R > version.string R version 2.7.0 (2008-04-22) > > > vQ > > -- > ------------------------------------------------------------------------------- > Wacek Kusnierczyk, MD PhD > > Email: waku at idi.ntnu.no > Phone: +47 73591875, +47 72574609 > > Department of Computer and Information Science (IDI) > Faculty of Information Technology, Mathematics and Electrical Engineering (IME) > Norwegian University of Science and Technology (NTNU) > Sem Saelands vei 7, 7491 Trondheim, Norway > Room itv303 > > Bioinformatics & Gene Regulation Group > Department of Cancer Research and Molecular Medicine (IKM) > Faculty of Medicine (DMF) > Norwegian University of Science and Technology (NTNU) > Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway > Room 231.05.060 > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
it's the assignment y[11] = 11 that causes y to become num:
y = 1:10
is(y) # integer vector numeric
y[11] = 11
is(y) # numeric vector
y = (1:11)[1:10]
is(y) # integer vector numeric
anyway, i think this should be considered a bug. the conversion is
irrational in this case.
this touches another issue discussed before, that of literals like '1'
not being treated as representing integers:
is(1) # numeric vector
is(1:1) # integer vector numeric
thus 1:10 is a vector of integers, but 11 is not an integer, and y[11] 11 makes
y not an integer vector.
one could actually defend r along these lines, but then there is an
inconsistency here.
help(":") says, among others, about the value of an expression of the
form 'from:to':
For numeric arguments, a numeric vector. This will be of type
'integer' if 'from' and 'to' are both integers and
representable
in the integer type, otherwise of type 'numeric'.
well, since is(1) does not report 1 to be an integer (even if the value
is representable as an integer), then 1:1 should not evalluate to an
integer vector.
the problem here is the notorious confusion between integers as numbers
with integers as representations of numbers, both in the docs and in the
design; the issue has been discussed before.
i think that from the point of view of most r users, this would be
consistent:
is(1) # integer vector numeric
is(1:1) # integer vector numeric
or this:
is(1) # numeric vector
is(1:1) # numeric vector
i find the following confused:
is(1.0) # numeric vector
is(1.0:1.0) # integer vector numeric
and the following a bug:
is(1.0:1.1) # integer vector numeric
(1.1 is certainly *not* an integer and certainly *not* representable in
an integer type)
and back to the original problem, even though you can explain it away
with the implicit conversion, i still find the behaviour of identical
irrational, since:
identical(1, 1.0)
[1] TRUE
so that there should be nothing wrong in identical(x,y) returning TRUE
after y = y[1:10].
vQ
markleeds at verizon.net wrote:> the str function shows that x is an int and y is a num so it's
> probably not a bug. or maybe the conversion to num is but probably
> not the identical.
>
> x = 1:10
> y = 1:10
>
> all.equal(x,y)
> identical(x,y)
>
> y[11] = 11
> y = y[1:10]
>
> all.equal(x,y)
> identical(x,y)
>
> print(str(y))
> print(str(x))
smells bad design. jim holtman wrote:> If you want them to be identical, then you have to explicitly assign > an integer to the vector so that conversion is not done: > > >> x = 1:10 >> y = 1:10 >> >> all.equal(x,y) >> > [1] TRUE > >> identical(x,y) >> > [1] TRUE > >> y[11] = 11L >> y = y[1:10] >> >> all.equal(x,y) >> > [1] TRUE > >> identical(x,y) >> > [1] TRUE > > > > On Sun, Oct 26, 2008 at 6:39 PM, Wacek Kusnierczyk > <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote: > >> given what ?identical says, i find the following odd: >> >> x = 1:10 >> y = 1:10 >> >> all.equal(x,y) >> [1] TRUE >> identical(x,y) >> [1] TRUE >> >> y[11] = 11 >> y = y[1:10] >> >> all.equal(x,y) >> [1] TRUE >> identical(x,y) >> [1] FALSE >> >> y >> [1] 1 2 3 4 5 6 7 8 9 10 >> length(y) >> [1] 10 >> >> >> looks like a bug. >> >> platform i686-pc-linux-gnu >> arch i686 >> os linux-gnu >> system i686, linux-gnu >> status >> major 2 >> minor 7.0 >> year 2008 >> month 04 >> day 22 >> svn rev 45424 >> language R >> version.string R version 2.7.0 (2008-04-22) >> >> >> vQ >> >> -- >> ------------------------------------------------------------------------------- >> Wacek Kusnierczyk, MD PhD >> >> Email: waku at idi.ntnu.no >> Phone: +47 73591875, +47 72574609 >> >> Department of Computer and Information Science (IDI) >> Faculty of Information Technology, Mathematics and Electrical Engineering (IME) >> Norwegian University of Science and Technology (NTNU) >> Sem Saelands vei 7, 7491 Trondheim, Norway >> Room itv303 >> >> Bioinformatics & Gene Regulation Group >> Department of Cancer Research and Molecular Medicine (IKM) >> Faculty of Medicine (DMF) >> Norwegian University of Science and Technology (NTNU) >> Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway >> Room 231.05.060 >> >> ______________________________________________ >> 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. >> >> > > > >-- ------------------------------------------------------------------------------- Wacek Kusnierczyk, MD PhD Email: waku at idi.ntnu.no Phone: +47 73591875, +47 72574609 Department of Computer and Information Science (IDI) Faculty of Information Technology, Mathematics and Electrical Engineering (IME) Norwegian University of Science and Technology (NTNU) Sem Saelands vei 7, 7491 Trondheim, Norway Room itv303 Bioinformatics & Gene Regulation Group Department of Cancer Research and Molecular Medicine (IKM) Faculty of Medicine (DMF) Norwegian University of Science and Technology (NTNU) Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway Room 231.05.060