Re: [R] Confusing concept of vector and matrix in R

2010-04-27 Thread Patrick Burns

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=FALSE]

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.

On 27/04/2010 03:36, Stuart Andrews wrote:


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:

 > ls(nonsense="42")
Error in ls(nonsense = "42") : unused argument(s) (nonsense = "42")

Cheers,
- Stu


On Apr 26, 2010, at 9:40 PM, Charles C. Berry wrote:


On Mon, 26 Apr 2010, Stu wrote:


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].


Wrong.


a <- structure(1:5,dim=5)
dim(a)

[1] 5

dim(a[2:3,drop=F]) # don't drop regardless

[1] 2

dim(a[2,drop=F]) # dont' drop regardless

[1] 1

dim(a[2:3,drop=T]) # no extent of length 1

[1] 2

dim(a[2,drop=T]) # drop, extent of length 1

NULL




Why doesn't R complain about the unused "drop=F" argument in the
single index case?


In the example you give (one index for a two-dimension array), vector
indexing is assumed. For vector indexing, drop is irrelevant.

HTH,

Chuck


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)


On Mar 30, 4:08 pm, lith  wrote:

Reframe the problem. Rethink why you need to keep dimensions. I
never ever had to use drop.


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"

__
r-h...@r-project.org mailing
listhttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting
guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@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.



Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901



__
R-help@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.



--
Patrick Burns
pbu...@pburns.seanet.com
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Peter Ehlers

On 2010-04-26 20:05, Matthew Keller wrote:

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.


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



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



On Mon, Apr 26, 2010 at 7:40 PM, Charles C. Berry  wrote:

On Mon, 26 Apr 2010, Stu wrote:


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].


Wrong.


a<- structure(1:5,dim=5)
dim(a)


[1] 5


dim(a[2:3,drop=F]) # don't drop regardless


[1] 2


dim(a[2,drop=F]) # dont' drop regardless


[1] 1


dim(a[2:3,drop=T]) # no extent of length 1


[1] 2


dim(a[2,drop=T]) # drop, extent of length 1


NULL




Why doesn't R complain about the unused "drop=F" argument in the
single index case?


In the example you give (one index for a two-dimension array), vector
indexing is assumed. For vector indexing, drop is irrelevant.

HTH,

Chuck


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)


On Mar 30, 4:08Â pm, lith  wrote:


Reframe the problem. Rethink why you need to keep dimensions. I never
ever had to use drop.


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"

__
r-h...@r-project.org mailing
listhttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting
guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@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.



Charles C. Berry                            (858) 534-2098
                                           Dept of 
Family/Preventive
Medicine
E mailto:cbe...@tajo.ucsd.edu               UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ Â La Jolla, San Diego 92093-0901


__
R-help@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.








--
Peter Ehlers
University of Calgary

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Charles C. Berry

On Mon, 26 Apr 2010, Stuart Andrews wrote:



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?


I take your point that user who was intending to type a vector subscript 
would not also bother to type 'drop=FALSE', 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.



For example, when I add an unrecognized argument to the ls() function I get 
the following:



 ls(nonsense="42")

Error in ls(nonsense = "42") : unused argument(s) (nonsense = "42")


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



y <- rnorm(3)
x <- 1:3
lm(y~x,data=list("blah"))


which arguably reveals a mistake by the user of the kind that having the 
unneeded 'drop=FALSE' suggested.


HTH,

Chuck



Cheers,
- Stu


On Apr 26, 2010, at 9:40 PM, Charles C. Berry wrote:


On Mon, 26 Apr 2010, Stu wrote:

> 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].

Wrong.

> a <- structure(1:5,dim=5)
> dim(a)
[1] 5
> dim(a[2:3,drop=F]) # don't drop regardless
[1] 2
> dim(a[2,drop=F]) # dont' drop regardless
[1] 1
> dim(a[2:3,drop=T]) # no extent of length 1
[1] 2
> dim(a[2,drop=T]) # drop, extent of length 1
NULL


> 
> Why doesn't R complain about the unused "drop=F" argument in the

> single index case?

In the example you give (one index for a two-dimension array), vector 
indexing is assumed. For vector indexing, drop is irrelevant.


HTH,

Chuck
> 
> 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)
> 
> 
> On Mar 30, 4:08 pm, lith  wrote:
> > > Reframe the problem. Rethink why you need to keep dimensions. I never 
> > > ever had to use drop.
> > 
> > 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"
> > 
> > __
> > r-h...@r-project.org mailing 
> > listhttps://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting 
> > guidehttp://www.R-project.org/posting-guide.html

> > and provide commented, minimal, self-contained, reproducible code.
> 
> __

> R-help@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.
> 


Charles C. Berry(858) 534-2098
   Dept of Family/Preventive 
Medicine

E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901





Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLE

Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Stuart Andrews


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:


> ls(nonsense="42")
Error in ls(nonsense = "42") : unused argument(s) (nonsense = "42")

Cheers,
- Stu


On Apr 26, 2010, at 9:40 PM, Charles C. Berry wrote:


On Mon, 26 Apr 2010, Stu wrote:


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].


Wrong.


a <- structure(1:5,dim=5)
dim(a)

[1] 5

dim(a[2:3,drop=F]) # don't drop regardless

[1] 2

dim(a[2,drop=F]) # dont' drop regardless

[1] 1

dim(a[2:3,drop=T]) # no extent of length 1

[1] 2

dim(a[2,drop=T]) # drop, extent of length 1

NULL




Why doesn't R complain about the unused "drop=F" argument in the
single index case?


In the example you give (one index for a two-dimension array),  
vector indexing is assumed. For vector indexing, drop is irrelevant.


HTH,

Chuck


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)


On Mar 30, 4:08 pm, lith  wrote:
Reframe the problem. Rethink why you need to keep dimensions. I  
never ever had to use drop.


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"

__
r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/ 
listinfo/r-help

PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@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.



Charles C. Berry(858) 534-2098
   Dept of Family/Preventive  
Medicine

E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego  
92093-0901




__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Matthew Keller
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



On Mon, Apr 26, 2010 at 7:40 PM, Charles C. Berry  wrote:
> On Mon, 26 Apr 2010, Stu wrote:
>
>> 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].
>
> Wrong.
>
>> a <- structure(1:5,dim=5)
>> dim(a)
>
> [1] 5
>>
>> dim(a[2:3,drop=F]) # don't drop regardless
>
> [1] 2
>>
>> dim(a[2,drop=F]) # dont' drop regardless
>
> [1] 1
>>
>> dim(a[2:3,drop=T]) # no extent of length 1
>
> [1] 2
>>
>> dim(a[2,drop=T]) # drop, extent of length 1
>
> NULL
>
>
>>
>> Why doesn't R complain about the unused "drop=F" argument in the
>> single index case?
>
> In the example you give (one index for a two-dimension array), vector
> indexing is assumed. For vector indexing, drop is irrelevant.
>
> HTH,
>
> Chuck
>>
>> 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)
>>
>>
>> On Mar 30, 4:08 pm, lith  wrote:

 Reframe the problem. Rethink why you need to keep dimensions. I never
 ever had to use drop.
>>>
>>> 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"
>>>
>>> __
>>> r-h...@r-project.org mailing
>>> listhttps://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting
>>> guidehttp://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> __
>> R-help@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.
>>
>
> Charles C. Berry                            (858) 534-2098
>                                            Dept of Family/Preventive
> Medicine
> E mailto:cbe...@tajo.ucsd.edu               UC San Diego
> http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
>
>
> __
> R-help@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.
>
>



-- 
Matthew C Keller
Asst. Professor of Psychology
University of Colorado at Boulder
www.matthewckeller.com

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Charles C. Berry

On Mon, 26 Apr 2010, Stu wrote:


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].


Wrong.


a <- structure(1:5,dim=5)
dim(a)

[1] 5

dim(a[2:3,drop=F]) # don't drop regardless

[1] 2

dim(a[2,drop=F]) # dont' drop regardless

[1] 1

dim(a[2:3,drop=T]) # no extent of length 1

[1] 2

dim(a[2,drop=T]) # drop, extent of length 1

NULL




Why doesn't R complain about the unused "drop=F" argument in the
single index case?


In the example you give (one index for a two-dimension array), vector 
indexing is assumed. For vector indexing, drop is irrelevant.


HTH,

Chuck


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)


On Mar 30, 4:08 pm, lith  wrote:

Reframe the problem. Rethink why you need to keep dimensions. I never ever had 
to use drop.


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"

__
r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Stu
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)


On Mar 30, 4:08 pm, lith  wrote:
> > Reframe the problem. Rethink why you need to keep dimensions. I never ever 
> > had to use drop.
>
> 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"
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-01 Thread Johannes Huesing
Rolf Turner  [Tue, Mar 30, 2010 at 09:48:12PM CEST]:
[...]
> Who designed Excel?

Among others, Joel Spolsky. Is that an appeal to authority?




-- 
Johannes Hüsing   There is something fascinating about science. 
  One gets such wholesale returns of conjecture 
mailto:johan...@huesing.name  from such a trifling investment of fact.  
  
http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-03-30 Thread lith
> Reframe the problem. Rethink why you need to keep dimensions. I never ever 
> had to use drop.

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"

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-03-30 Thread Rolf Turner

On 30/03/2010, at 10:04 PM, Barry Rowlingson wrote:

> On Tue, Mar 30, 2010 at 2:42 AM, Rolf Turner  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
##

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-03-30 Thread Mario Valle
Reframe the problem. Rethink why you need to keep dimensions. I never ever had 
to use drop.
My .02 something
mario

Barry Rowlingson wrote:
> On Tue, Mar 30, 2010 at 2:42 AM, Rolf Turner  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!
> 
>  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
> 
> __
> R-help@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.

-- 
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

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-03-30 Thread Barry Rowlingson
On Tue, Mar 30, 2010 at 2:42 AM, Rolf Turner  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!

 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

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-03-29 Thread Sharpie


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
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-03-29 Thread Gabor Grothendieck
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]

On Mon, Mar 29, 2010 at 7:13 PM, 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!
> --
> View this message in context: 
> http://n4.nabble.com/Confusing-concept-of-vector-and-matrix-in-R-tp1707170p1707170.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-03-29 Thread Steve Lianoglou
> 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!

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,]159   13   17
[2,]26   10   14   18
[3,]37   11   15   19
[4,]48   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

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-03-29 Thread Rolf Turner

On 30/03/2010, at 12:13 PM, 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!


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
##

__
R-help@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.