[R] sub() of matrix returns a vector and not a matrix

Martin Maechler maechler at stat.math.ethz.ch
Tue May 7 16:25:48 CEST 2002


>>>>> "Wolfram" == "Wolfram Fischer <- Z/I/M" <wolfram at fischer-zim.ch>> writes:

    Wolfram> Is there a simple possibility to become directly a
    Wolfram> matrix from a call of sub() on a matrix?

This can be considered as a feature proposal which I would
second:

sub() and gsub() could be enhanced such as to keep attributes(.)
of their x argument.

The `dim' attribute which makes a vector into a matrix is just
one kind of attributes.

Opinions?


    >> a <- matrix( letters[1:6], 2, 3 )
    >> b <- sub( '(.)', '-\\1-', a )
    Wolfram> 	# I had expected b to be a matrix # but b is a  vector
    >> print( b )
    Wolfram> [1] "-a-" "-b-" "-c-" "-d-" "-e-" "-f-"

    >> dim(b) <- dim(a)
    >> print( b )
    Wolfram> # b is now a matrix again 
    ....

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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