Skip to content

subset of matrix vs data frame

3 messages · Denis White, Brian Ripley, Peter Dalgaard

#
In Splus this works,
but in R only if a is matrix,
Error in [<-.data.frame(*tmp*, a == 1, value = 2) : 
        matrix subscripts not allowed in replacement

Was this a design decision?  Sorry if I missed it in
An Introduction to R.

Denis
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 31 May 2000, Denis White wrote:

            
S-PLUS differs from the original S here, as I understand it.
So it was an S-PLUS design decision as I understand it. S-PLUS says:

        else if(nargs() == 3) {
# really ambiguous, but follow common use as if list, 
# except when one subscript is a logical matrix the shape of x, then treat
# as if x were a matrix.
#
Prof Brian D Ripley <ripley at stats.ox.ac.uk> writes:
Semantically it is a rather strange thing to do since elements
in different columns of a data matrix can be of different type. 
And some really weird stuff *does* happen in Splus 3.4:
Warning messages:
  replacement values not all in levels(x): NA's generated in:
i[, k, drop = T], value = .A1)
a  b  c 
 1  1  1 1 
 2  2  2 2 
 3  3  3 3 
 4  4  4 4 
 5  x NA x 
 6  6  6 6 
 7  7  7 7 
 8  8  8 8 
 9  9  9 9 
10 10 10 10
Warning messages:
1: Data length is not an even multiple of group length in:
factor(col(i)[i], levels = seq(len = ncol(i))))
2: replacement values not all in levels(x): NA's generated in:
A0, i[, k, drop = T], value = .A1)
3: replacement values not all in levels(x): NA's generated in:
A0, i[, k, drop = T], value = .A1)
a  b  c 
 1  1  1 1 
 2  2  2 2 
 3  3  3 3 
 4 NA NA 4 
 5  x NA x 
 6  6  6 6 
 7  7  7 7 
 8  8  8 8 
 9  9  9 9 
10 10 10 10