Wolfgang Huber
2010-Feb-12 17:50 UTC
[Rd] Unexpected behaviour of x[i] when i is a matrix, on Windows
Hi,
when running the following on different instances of R (Linux and
Windows), I get different results. The one for Linux seems to be the
intended / documented one. When using numeric indices rather than
characters, Windows seemed to behave as expected.
-----------On Windows--------------
x = matrix(FALSE, nrow=3, ncol=3)
colnames(x) = LETTERS[1:3]
rownames(x) = letters[1:3]
x
# A B C
# a FALSE FALSE FALSE
# b FALSE FALSE FALSE
# c FALSE FALSE FALSE
x [ cbind("b", "B") ] = TRUE
x
b B
# FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE
sessionInfo()
R version 2.10.0 (2009-10-26)
i386-pc-mingw32
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
-----------On Linux--------------
x = matrix(FALSE, nrow=3, ncol=3)
colnames(x) = LETTERS[1:3]
rownames(x) = letters[1:3]
x
# A B C
# a FALSE FALSE FALSE
# b FALSE FALSE FALSE
# c FALSE FALSE FALSE
x [ cbind("b", "B") ] = TRUE
x
# A B C
# a FALSE FALSE FALSE
# b FALSE TRUE FALSE
# c FALSE FALSE FALSE
> sessionInfo()
R version 2.11.0 Under development (unstable) (2010-02-12 r51125)
x86_64-unknown-linux-gnu
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] fortunes_1.3-7
--
Best wishes
Wolfgang
--
Wolfgang Huber
EMBL
http://www.embl.de/research/units/genome_biology/huber/contact
Peter Ehlers
2010-Feb-12 18:12 UTC
[Rd] Unexpected behaviour of x[i] when i is a matrix, on Windows
You're comparing 2.10.0 on Windows with 2.11.0 on Linux. Have you tried 2.11.0 on Windows? => same result as on Linux. -Peter Ehlers Wolfgang Huber wrote:> Hi, > > when running the following on different instances of R (Linux and > Windows), I get different results. The one for Linux seems to be the > intended / documented one. When using numeric indices rather than > characters, Windows seemed to behave as expected. > > -----------On Windows-------------- > > x = matrix(FALSE, nrow=3, ncol=3) > colnames(x) = LETTERS[1:3] > rownames(x) = letters[1:3] > x > > # A B C > # a FALSE FALSE FALSE > # b FALSE FALSE FALSE > # c FALSE FALSE FALSE > > x [ cbind("b", "B") ] = TRUE > x > b B > # FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE > > sessionInfo() > > R version 2.10.0 (2009-10-26) > i386-pc-mingw32 > > locale: > [1] LC_COLLATE=English_United States.1252 > [2] LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 > [4] LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > > -----------On Linux-------------- > x = matrix(FALSE, nrow=3, ncol=3) > colnames(x) = LETTERS[1:3] > rownames(x) = letters[1:3] > x > # A B C > # a FALSE FALSE FALSE > # b FALSE FALSE FALSE > # c FALSE FALSE FALSE > x [ cbind("b", "B") ] = TRUE > x > # A B C > # a FALSE FALSE FALSE > # b FALSE TRUE FALSE > # c FALSE FALSE FALSE > > > sessionInfo() > R version 2.11.0 Under development (unstable) (2010-02-12 r51125) > x86_64-unknown-linux-gnu > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=en_US.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices datasets utils methods base > > other attached packages: > [1] fortunes_1.3-7 > > > >-- Peter Ehlers University of Calgary
Simon Urbanek
2010-Feb-12 18:15 UTC
[Rd] Unexpected behaviour of x[i] when i is a matrix, on Windows
On Feb 12, 2010, at 12:50 , Wolfgang Huber wrote:> Hi, > > when running the following on different instances of R (Linux and > Windows), I get different results. The one for Linux seems to be the > intended / documented one. When using numeric indices rather than > characters, Windows seemed to behave as expected. >AFAICT this has nothing to do with the platform but with using an older R version in Windows that doesn't support it ... From NEWS: CHANGES IN R VERSION 2.11.0 [...] NEW FEATURES [...] o n-dimensional arrays with dimension names can now be indexed by an n-column character matrix. The indices are matched against the dimension names. NA indices are propagated to the result. Unmatched values and "" are not allowed and result in an error. Cheers, Simon> -----------On Windows-------------- > > x = matrix(FALSE, nrow=3, ncol=3) > colnames(x) = LETTERS[1:3] > rownames(x) = letters[1:3] > x > > # A B C > # a FALSE FALSE FALSE > # b FALSE FALSE FALSE > # c FALSE FALSE FALSE > > x [ cbind("b", "B") ] = TRUE > x > b B > # FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE > > sessionInfo() > > R version 2.10.0 (2009-10-26) > i386-pc-mingw32 > > locale: > [1] LC_COLLATE=English_United States.1252 > [2] LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 > [4] LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > > -----------On Linux-------------- > x = matrix(FALSE, nrow=3, ncol=3) > colnames(x) = LETTERS[1:3] > rownames(x) = letters[1:3] > x > # A B C > # a FALSE FALSE FALSE > # b FALSE FALSE FALSE > # c FALSE FALSE FALSE > x [ cbind("b", "B") ] = TRUE > x > # A B C > # a FALSE FALSE FALSE > # b FALSE TRUE FALSE > # c FALSE FALSE FALSE > > > sessionInfo() > R version 2.11.0 Under development (unstable) (2010-02-12 r51125) > x86_64-unknown-linux-gnu > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=en_US.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices datasets utils methods base > > other attached packages: > [1] fortunes_1.3-7 > > > > > -- > > Best wishes > Wolfgang > > > -- > Wolfgang Huber > EMBL > http://www.embl.de/research/units/genome_biology/huber/contact > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >