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
######################################################################
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
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
Actually R looks at it the other way around. It regards a matrix as a
special case of a vector. A vector has no dimensions. A vector with
dimensions is an array. An array with two dimensions is a matrix.
Try using drop=FALSE like this:
m <- matrix(1:6, 3)
m[, 2, drop = FALSE]
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
Reframe the problem. Rethink why you need to keep dimensions. I never ever had to use drop.
My .02 something
mario
--
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
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.
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"
Rolf Turner <r.turner*******> [Tue, Mar 30, 2010 at 09:48:12PM CEST]:
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:johannes******* (Mark Twain, "Life on the Mississippi")
______________________________________________
R-help*******/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.
Hi all,
One subtlety is that the drop argument only works if you specify 2 or
more indices e.g. [i, j, ..., drop=F]; but not for a single index e.g
[i, drop=F].
Why doesn't R complain about the unused "drop=F" argument in the
single index case?
Cheers,
- Stu
a = matrix(1:10, nrow=1)
b = matrix(10:1, ncol=1)
# a1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(a1 = a[2:5, drop=F])
dim(a1)
# a2 is an vector WITH dim attribute: a row matrix (drop=F works)
(a2 = a[, 2:5, drop=F])
dim(a2)
# b1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(b1 = b[2:5, drop=F])
dim(b1)
# b2 is an vector WITH dim attribute: a column matrix (drop=F works)
(b2 = b[2:5, , drop=F])
dim(b2)
Wrong.
[1] 5
[1] 2
[1] 1
[1] 2
In the example you give (one index for a two-dimension array), vector
indexing is assumed. For vector indexing, drop is irrelevant.
HTH,
Chuck
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry*******/faculty/cberry/ La Jolla, San Diego 92093-0901
Rolf: "Well then, why don't you go away and design and build your own
statistics and data analysis language/package to replace R?"
What a nice reply! The fellow is just trying to understand R. That
response reminds me of citizens of my own country who cannot abide by
any criticism of the USA: "If you don't like it, why don't you leave?"
Classy.
I have sympathies with the author. When I first began using R
(migrating from Matlab), I also found the vector concept strange,
especially because I was doing a lot of matrix algebra back then and
didn't like the concept of conflating a row vector with a column
vector. But I've since gotten used to it and can hardly remember why I
struggled with this early on. Perhaps your experience will be similar.
Best of luck!
Matt
--
Matthew C Keller
Asst. Professor of Psychology
University of Colorado at Boulder
www.matthewckeller.com
______________________________________________
R-help*******/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.
Thanks Charles, for clarifying.
My statement holds for matrices, which are 2 dimensional. And, as you
mentioned, a single index implies vector indexing where the drop
argument doesn't make sense. I am somewhat relieved, given this new
understanding.
But I am still puzzled as to why R doesn't complain about the unused
"drop=F" argument. Since this argument is nonsensical, R should tell
me this, no? For example, when I add an unrecognized argument to the
ls() function I get the following:
Error in ls(nonsense = "42") : unused argument(s) (nonsense = "42")
Cheers,
- Stu
I take your point that user who was intending to type a vector subscript
would not also bother to type 'dropúLSE', and from the POV of the user
typing "a[1:3,drop=F]" at the keyboard, it makes good sense to me to have
R tip him/her off to a potential goof.
But subscripts get used a lot down deep in the code, so there are other
considerations, I suspect. If you are interested in this from a 'code
development' POV, you might repost to R-devel to ask what might have lead
to this 'feature'. I have two guesses:
1) subscripting is a pretty low-level operation and checking for this
particular case is not important enough to justify the added code and
perhaps slowing things down.
2) a construction like
do.call("[", c(list(x), args, list(drop = FALSE)))
will work without comment as long as the 'args' argument delivers a valid
subscript or set of subscripts (valid for 'x') and the drop = FALSE
will always be innocuous even if it is superfluous.
Priorities! Failure of argument matching is a critical error. Having a
valid but superfluous argument is not, and there are loads of settings in
which no error is raised like
which arguably reveals a mistake by the user of the kind that having the
unneeded 'dropúLSE' suggested.
HTH,
Chuck
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry*******/faculty/cberry/ La Jolla, San Diego 92093-0901
Let's not take things too far out of context. Rolf was replying
to someone who was 'very annoyed' that R has the concept of a
vector. That poster felt that, since a vector is just a special
case of a matrix, there was no need for the vector concept. That
poster had also not yet read enough to realize that there *is*
the 'drop=FALSE' argument.
It's a bit strong to complain that R was not designed to suit
your own needs and yours alone, never mind what others might
think.
I have found R-core to be quite receptive to intelligent and
well thought-out suggestions. But "It is very annoying!" is
not the right approach.
-Peter Ehlers
--
Peter Ehlers
University of Calgary
Two points:
the 'drop' argument is not unrecognized,
just superfluous.
There are one-dimensional cases where the
'drop' argument is not superfluous:
factor(letters)[1:5, drop=TRUE]
factor(letters)[1:5, dropúLSE]
So my guess is that it would be an exceptional
amount of work to get such a warning correct,
and would possibly cause a substantial performance
hit in one of the most used functions in the
language.
--
Patrick Burns
pburns*******
(home of 'Some hints for the R beginner'
and 'The R Inferno')