[R] subset of matrix vs data frame
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Wed May 31 21:30:03 CEST 2000
On Wed, 31 May 2000, Denis White wrote:
> In Splus this works,
>
> > a <- data.frame(matrix(round(runif(10),0),nrow=2,ncol=5))
> > a[a == 1] <- 2
>
> but in R only if a is matrix,
>
> > a[a == 1] <- 2
> 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.
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.
--
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list