Dear Duncan,

you are right. In both R 2.2.0 and 2.1.1 you get the same result. What has 
actually changed is the following:
In R 2.1.1
> mat[1, , drop = FALSE][1]
r1 
 1 

While in R 2.2.0
> mat[1, , drop = FALSE][1]
[1] 1

In both cases
> mat[1, , drop = FALSE]
   c1 c2 c3
r1  1  4  7

I would strongly prefer to retain the row index r1 above.
Of course, you could argue that mat[1, , drop = FALSE][1] relates to the 
column name c1. However, I think the lower dimension is a vector and this 
typically a column with row names. Most likely, a  wiser and more concise 
interpretation than the mine is necessary, but the problem of dropping and 
loosing information is quite evident in any case.

Still, I believe, my suggestion below is justified. Things like this 
happen quite often to me and it regularly takes time and effort to rectify 
the problem.
Retaining the matrix features in sames could really be an advantage and 
avoid many if's and other workarounds.

Many thanks and best regards,
Stefan



Duncan Murdoch <murdoch@stats.uwo.ca> 
2005-10-18 14:33

An
stefan.albrecht@allianz.com
Kopie
r-devel@stat.math.ethz.ch, R-bugs@biostat.ku.dk
Thema
Re: [Rd] Inconsistency with matrix indexing (PR#8214)






stefan.albrecht@allianz.com wrote:
> Full_Name: Stefan Albrecht
> Version: 2.2.0
> OS: Windows XP
> Submission from: (NULL) (194.127.2.74)
> 
> 
> Dear all,
> 
> in the new R 2.2.0, the matrix indexing has been changed.

I just tried your code in R 2.0.1 and 2.1.1, and got the same output as 
you did.  Which version are you comparing to?

Duncan Murdoch


  In my opinion, this
> leads to an inconsistency when indexing one-row matrices.
> Take
> 
>>(mat <- matrix(1:9, nrow = 3, dimnames = list(paste("r", 1:3, sep = ""),
> 
> paste("c", 1:3, sep = ""))))
>    c1 c2 c3
> r1  1  4  7
> r2  2  5  8
> r3  3  6  9
> 
> Now taking the first row of the first-row of mat preserves the column 
names
> 
>>mat[1, , drop = FALSE][1, ]
> 
> c1 c2 c3 
>  1  4  7 
> 
> This is not true for the first column of the first-row of mat
> 
>>mat[1, , drop = FALSE][, 1]
> 
> [1] 1
> 
> However, for the first column of the first two rows of mat the row names 
are
> retained
> 
>>mat[1:2, , drop = FALSE][, 1]
> 
> r1 r2 
>  1  2 
> 
> This feature can lead to problems when indexing matrixes of different 
row
> numbers, since the row names are not preserved in all cases.
> 
> I suggest to preseve the row names also for 
> 
>>mat[1, , drop = FALSE][, 1]
> 
> 
> Would it be possible to implement this feature? Many thanks.
> 
> With best regards,
> 
> Stefan Albrecht
> 
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



	[[alternative HTML version deleted]]

