______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
>
> Why does R need the concept of "Vector"? In my opinion, it is a useless and
> confusing concept. A vector is simply a special case of a matrix whose row
> or column number is equal to 1. When I take submatrix from one matrix and
> if row or column number is 1, R will automatically convert it into a vector.
> It is very straightforward that a submatrix of a matrix should be a matrix.
> In each time, I have to use as.matrix() to convert the vector back to
> matrix. It is very annoying!
Well then, why don't you go away and design and build your own statistics and
data analysis language/package to replace R? You can then make whatever
design decisions you like, and you won't have to live with the design decisions
made by such silly and inept people as John Chambers and Rick Becker and their ilk.
cheers,
Rolf Turner
######################################################################
Attention:
This e-mail message is privileged and confidential. If you are not the
intended recipient please delete the message and notify the sender.
Any views or opinions presented are solely those of the author.
This e-mail has been scanned and cleared by MailMarshal
www.marshalsoftware.com
######################################################################
yehengxin wrote:
>
> Why does R need the concept of "Vector"? In my opinion, it is a useless
> and confusing concept. A vector is simply a special case of a matrix
> whose row or column number is equal to 1. When I take submatrix from one
> matrix and if row or column number is 1, R will automatically convert it
> into a vector. It is very straightforward that a submatrix of a matrix
> should be a matrix. In each time, I have to use as.matrix() to convert
> the vector back to matrix. It is very annoying!
>
Except that to a computer all "matricies" and "arrays" are just vectors for
which some human arbitrarily declared something like "row break every n
entries".
And R can be told not to perform the conversion from sub-matrix to vector,
open the help page for the subset operator:
?"["
And play with the drop option.
-Charlie
-----
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
--
View this message in context: http://n4.nabble.com/Confusing-concept-of-vector-and-matrix-in-R-tp1707170p1735190.html
Good thing there's a way to get around this then:
R> m <- matrix(1:20, 4, 5)
R> m
[,1] [,2] [,3] [,4] [,5]
[1,] 1 5 9 13 17
[2,] 2 6 10 14 18
[3,] 3 7 11 15 19
[4,] 4 8 12 16 20
R> m[,1]
[1] 1 2 3 4
R> m[,1,drop=FALSE]
[,1]
[1,] 1
[2,] 2
[3,] 3
[4,] 4
R> is.matrix(m[,1,drop=FALSE])
[1] TRUE
-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
Try using drop=FALSE like this:
m <- matrix(1:6, 3)
m[, 2, drop = FALSE]
> Well then, why don't you go away and design and build your own statistics and
> data analysis language/package to replace R? You can then make whatever
> design decisions you like, and you won't have to live with the design decisions
> made by such silly and inept people as John Chambers and Rick Becker and their ilk.
Aah, argument by (ironic) reference to learned authority!
Even Einstein was wrong ("God does not play dice"). He was also
right, thought he was wrong, and then we've discovered he may have
been right all along (The Cosmological Constant, Dark Energy etc).
How many of us have _never_ interfaced our foreheads with the
keyboard when something breaks because we didn't put ",drop=FALSE" in
a matrix subscript?
There is no doubt that R plays fast and loose with many concepts of
type and structure that Computer Scientists would turn their nose up
at. I would love to go away and redesign it, but I'd just end up with
python. Truth is that R's statistical power is what makes it great
because of the vast wealth of CRAN, not the R language per se with its
"features" that so fluster my comp-sci friends. And many a beginner.
We work round them by bashing our heads on the keyboards, typing
",drop=FALSE", and vowing never to do it again. And writing more unit
tests.
Barry
--
Ing. Mario Valle
Data Analysis and Visualization Group | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
> On Tue, Mar 30, 2010 at 2:42 AM, Rolf Turner <r.tu...@auckland.ac.nz> wrote:
>
>> Well then, why don't you go away and design and build your own statistics and
>> data analysis language/package to replace R? You can then make whatever
>> design decisions you like, and you won't have to live with the design decisions
>> made by such silly and inept people as John Chambers and Rick Becker and their ilk.
>
> Aah, argument by (ironic) reference to learned authority!
Not at all. I was not arguing about the correctness of the design, decisions.
I was objecting to the churlish tone and the fatuousness of the complaint. The
design decisions, right or wrong, were taken a long time ago, and are impossible
to change now. So if you don't like 'em, there's now't to be done but go build
your own package.
That being said, learned authority is not always correct but has a strong tendency
to be so. Decisions made by learned authority may be disputed but one should be
very sure that one knows what the whuck (Maori spelling :-) ) one is talking about
before disputing. Cf. fortune("matter of opinion").
As regards features of R flustering comp-sci people: So many dysfunctional pieces
of software are designed by arrogant computer scientists who do not actually *use*
that software, do not know the background of the area of application, and do not
understand the area of application. I'll go with stats software designed by
statisticians rather than computer scientists any day. Who designed Excel?
cheers,
Rolf
######################################################################
Attention:
This e-mail message is privileged and confidential. If you are not the
intended recipient please delete the message and notify the sender.
Any views or opinions presented are solely those of the author.
This e-mail has been scanned and cleared by MailMarshal
www.marshalsoftware.com
######################################################################
______________________________________________
The problem is that the type of the return value changes if you happen
to forget to use drop = FALSE, which can easily turn into a nightmare:
m <- matrix(1:20, ncol=4)
for (i in seq(3, 1, -1)) {
print(class(m[1:i, ]))
}
[1] "matrix"
[1] "matrix"
[1] "integer"
Among others, Joel Spolsky. Is that an appeal to authority?
<http://www.joelonsoftware.com/articles/fog0000000020.html>
--
Johannes Hüsing There is something fascinating about science.
One gets such wholesale returns of conjecture
mailto:joha...@huesing.name from such a trifling investment of fact.
http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")