Re: [R] The end of Matlab

2008-12-12 Thread hadley wickham
On Fri, Dec 12, 2008 at 3:08 PM, Vitalie Spinu wrote: > On Fri, 12 Dec 2008 18:27:02 +0100, hadley wickham > wrote: > > >>> or may be just >>> mtcars[cyl>3&last(20)] >>> >>> or this is already too far? >> >> This would be a considerable extension because then the selector would >> need to know ab

Re: [R] The end of Matlab

2008-12-12 Thread Vitalie Spinu
On Fri, 12 Dec 2008 18:27:02 +0100, hadley wickham wrote: or may be just mtcars[cyl>3&last(20)] or this is already too far? This would be a considerable extension because then the selector would need to know about all other variables in the dataset, and you'd need someway of combining selec

Re: [R] The end of Matlab

2008-12-12 Thread hadley wickham
> My end would be the output of your end(). If there are no args and no local > context, I don't see the need for it to be a function call. It would just > be defined as something like > > end <- structure( function(n) c(rep(FALSE, n-1), TRUE), class="selector") Oh, I see what you mean. > I'm n

Re: [R] The end of Matlab

2008-12-12 Thread Greg Snow
; project.org] On Behalf Of Claudia Beleites > Sent: Friday, December 12, 2008 11:38 AM > To: r-help@r-project.org > Subject: Re: [R] The end of Matlab > > > evens() & last(5) > wouldn't x[evens()][last(5)] do the & already? > > or is different, though. >

Re: [R] The end of Matlab

2008-12-12 Thread Claudia Beleites
> evens() & last(5) wouldn't x[evens()][last(5)] do the & already? or is different, though. Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 (0 40) 5 58-34 47 email: cbelei...@un

Re: [R] The end of Matlab

2008-12-12 Thread Duncan Murdoch
On 12/12/2008 1:06 PM, hadley wickham wrote: Oh yes, that's a good point. But wouldn't the following do the job? "&.selector" <- function(a, b) { function(n) a(n) & b(n) } or "&.selector" <- function(a, b) { function(n) intersect(a(n), b(n)) } depending on whether selectors return logical

Re: [R] The end of Matlab

2008-12-12 Thread hadley wickham
>> Oh yes, that's a good point. But wouldn't the following do the job? >> >> "&.selector" <- function(a, b) { >> function(n) a(n) & b(n) >> } >> >> or >> >> "&.selector" <- function(a, b) { >> function(n) intersect(a(n), b(n)) >> } >> >> depending on whether selectors return logical or numeric v

Re: [R] The end of Matlab

2008-12-12 Thread Duncan Murdoch
On 12/12/2008 12:23 PM, hadley wickham wrote: On Fri, Dec 12, 2008 at 11:18 AM, Duncan Murdoch wrote: On 12/12/2008 11:38 AM, hadley wickham wrote: On Fri, Dec 12, 2008 at 8:41 AM, Duncan Murdoch wrote: On 12/12/2008 8:25 AM, hadley wickham wrote: From which you might conclude that I don

Re: [R] The end of Matlab

2008-12-12 Thread Gabor Grothendieck
On Fri, Dec 12, 2008 at 12:11 PM, Vitalie Spinu wrote: > On Fri, 12 Dec 2008 17:38:13 +0100, hadley wickham > wrote: > >> You could also imagine similar iterators for random sampling, like >> samp(0.2) to choose 20% of the indices, or boot(0.8) to choose 80% >> with replacement. first(n) could a

Re: [R] The end of Matlab

2008-12-12 Thread hadley wickham
On Fri, Dec 12, 2008 at 11:11 AM, Vitalie Spinu wrote: > On Fri, 12 Dec 2008 17:38:13 +0100, hadley wickham > wrote: > >> You could also imagine similar iterators for random sampling, like >> samp(0.2) to choose 20% of the indices, or boot(0.8) to choose 80% >> with replacement. first(n) could a

Re: [R] The end of Matlab

2008-12-12 Thread hadley wickham
On Fri, Dec 12, 2008 at 11:18 AM, Duncan Murdoch wrote: > On 12/12/2008 11:38 AM, hadley wickham wrote: >> >> On Fri, Dec 12, 2008 at 8:41 AM, Duncan Murdoch >> wrote: >>> >>> On 12/12/2008 8:25 AM, hadley wickham wrote: > > From which you might conclude that I don't like the design of su

Re: [R] The end of Matlab

2008-12-12 Thread Duncan Murdoch
On 12/12/2008 11:38 AM, hadley wickham wrote: On Fri, Dec 12, 2008 at 8:41 AM, Duncan Murdoch wrote: On 12/12/2008 8:25 AM, hadley wickham wrote: From which you might conclude that I don't like the design of subset, and you'd be right. However, I don't think this is a counterexample to my ge

Re: [R] The end of Matlab

2008-12-12 Thread Vitalie Spinu
On Fri, 12 Dec 2008 17:38:13 +0100, hadley wickham wrote: You could also imagine similar iterators for random sampling, like samp(0.2) to choose 20% of the indices, or boot(0.8) to choose 80% with replacement. first(n) could also be useful, selecting the first min(n, length(vector)) observatio

Re: [R] The end of Matlab

2008-12-12 Thread hadley wickham
On Fri, Dec 12, 2008 at 8:41 AM, Duncan Murdoch wrote: > On 12/12/2008 8:25 AM, hadley wickham wrote: >>> >>> From which you might conclude that I don't like the design of subset, and >>> you'd be right. However, I don't think this is a counterexample to my >>> general rule. In the subset functi

Re: [R] The end of Matlab

2008-12-12 Thread Greg Snow
k > Sent: Friday, December 12, 2008 8:57 AM > To: claudia.belei...@gmx.de > Cc: R help > Subject: Re: [R] The end of Matlab > > Claudia Beleites wrote: > >>> Wacek: > >>> > >>>> x[3:] > >>>> instead of > >>>&g

Re: [R] The end of Matlab

2008-12-12 Thread Wacek Kusnierczyk
Claudia Beleites wrote: >>> Wacek: >>> x[3:] instead of x[3:length(x)] x[3:end] >>> I don't think that would help: >>> what to use for end - 3 within the convention that negative values mean >>> exclusion? >>> >> might seem tricky, but not impossible:

Re: [R] The end of Matlab

2008-12-12 Thread Claudia Beleites
I just realized that my idea of doing something without going into the extraction functions itself won't work :-( it was a nice dream, though. The reason is that there is no general way to find out what the needed length is: At least I'm just writing a class where 2 kinds of columns are involve

Re: [R] The end of Matlab

2008-12-12 Thread Gabor Grothendieck
Here is how to emulate matlab end in R in the case of matrices. Rather than redefine the matrix class (which would be a bit intrusive) we just define a subclass of matrix called matrix2. Note in the examples that matrix2 survives some operations such as + but not others such as crossprod so in th

Re: [R] The end of Matlab

2008-12-12 Thread Claudia Beleites
> > Wacek: > >> x[3:] > >> instead of > >> x[3:length(x)] > >> x[3:end] > > > > I don't think that would help: > > what to use for end - 3 within the convention that negative values mean > > exclusion? > > might seem tricky, but not impossible: > > x[-2] > # could mean 'all except for 2nd', as it i

Re: [R] The end of Matlab

2008-12-12 Thread Wacek Kusnierczyk
>> Wacek: >> >> >>> x[3:] >>> instead of >>> x[3:length(x)] >>> x[3:end] >>> >>> >> I don't think that would help: >> what to use for end - 3 within the convention that negative values mean >> exclusion? >> >> >> >> > > might seem tricky, but not impossible: > > x[-2]

Re: [R] The end of Matlab

2008-12-12 Thread Duncan Murdoch
On 12/12/2008 8:25 AM, hadley wickham wrote: From which you might conclude that I don't like the design of subset, and you'd be right. However, I don't think this is a counterexample to my general rule. In the subset function, the select argument is treated as an unevaluated expression, and the

Re: [R] The end of Matlab

2008-12-12 Thread Wacek Kusnierczyk
Claudia Beleites wrote: > Am Freitag 12 Dezember 2008 13:10:20 schrieb Patrick Burns: > >> How about: >> >> x[, -seq(to=ncol(x), length=n)] >> > Doing it is not my problem. I just agree with Mike in that I would like if I > could do shorter than: > > x[, 1 : (ncol(x) - n)] > > which I bt

Re: [R] The end of Matlab

2008-12-12 Thread Claudia Beleites
Am Freitag 12 Dezember 2008 13:10:20 schrieb Patrick Burns: > How about: > > x[, -seq(to=ncol(x), length=n)] Doing it is not my problem. I just agree with Mike in that I would like if I could do shorter than: x[, 1 : (ncol(x) - n)] which I btw prefer to your solution. Also, I don't have a pro

Re: [R] The end of Matlab

2008-12-12 Thread hadley wickham
> From which you might conclude that I don't like the design of subset, and > you'd be right. However, I don't think this is a counterexample to my > general rule. In the subset function, the select argument is treated as an > unevaluated expression, and then there are rules about what to do with

Re: [R] The end of Matlab

2008-12-12 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: > On 11/12/2008 9:45 PM, Mike Rowe wrote: > >> >> this.matrix[3:end,end] >> >> would be equivalent to: >> >> this.matrix[3:nrow(this.matrix),ncol(this.matrix)] # or >> this.matrix[3:dim(this.matrix)[1],dim(this.matrix)[2]] >> >> As you can see, the R version requires more ty

Re: [R] The end of Matlab

2008-12-12 Thread Patrick Burns
How about: x[, -seq(to=ncol(x), length=n)] Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Claudia Beleites wrote: Dear list, Learning to use the power of R's indexing and functios like head() an

Re: [R] The end of Matlab

2008-12-12 Thread Claudia Beleites
Dear list, > Learning to use the power of R's indexing and functios like head() and > tail() (which are just syntactic sugar) will probably lead you not to miss > this. However, how do I exclude the last columns of a data.frame or matrix (or, in general, head and tail for given dimensions of an a

Re: [R] The end of Matlab

2008-12-12 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: > On 12/12/2008 3:41 AM, Wacek Kusnierczyk wrote: >> >> but this 'general rule' is not really adhered to in r! one example >> already discussed here at length is subset: >> >> subset(data.frame(...), select=a) >> >> what will be selected? column named "a", or columns named b

Re: [R] The end of Matlab

2008-12-12 Thread Duncan Murdoch
On 12/12/2008 3:41 AM, Wacek Kusnierczyk wrote: Duncan Murdoch wrote: On 11/12/2008 9:45 PM, Mike Rowe wrote: Greetings! I come to R by way of Matlab. One feature in Matlab I miss is its "end" keyword. When you put "end" inside an indexing expression, it is interpreted as the length of the v

Re: [R] The end of Matlab

2008-12-12 Thread Prof Brian Ripley
On Fri, 12 Dec 2008, Duncan Murdoch wrote: On 11/12/2008 9:45 PM, Mike Rowe wrote: Greetings! I come to R by way of Matlab. One feature in Matlab I miss is its "end" keyword. When you put "end" inside an indexing expression, it is interpreted as the length of the variable along the dimension

Re: [R] The end of Matlab

2008-12-12 Thread Wacek Kusnierczyk
Duncan Murdoch wrote: > On 11/12/2008 9:45 PM, Mike Rowe wrote: >> Greetings! >> >> I come to R by way of Matlab. One feature in Matlab I miss is its >> "end" keyword. When you put "end" inside an indexing expression, it >> is interpreted as the length of the variable along the dimension being >>

Re: [R] The end of Matlab

2008-12-11 Thread Duncan Murdoch
On 11/12/2008 9:45 PM, Mike Rowe wrote: Greetings! I come to R by way of Matlab. One feature in Matlab I miss is its "end" keyword. When you put "end" inside an indexing expression, it is interpreted as the length of the variable along the dimension being indexed. For example, if the same fea

Re: [R] The end of Matlab

2008-12-11 Thread Gabor Grothendieck
Its been pointed out to me that the second one is wrong. It should be: tail(this.matrix, -2)[, ncol(this.matrix)] which is not as compact as matlab or my prior post but still not particularly onerous. On Thu, Dec 11, 2008 at 11:49 PM, Gabor Grothendieck wrote: > Use tail and head. See interspe

Re: [R] The end of Matlab

2008-12-11 Thread Gabor Grothendieck
Use tail and head. See interspersed. On Thu, Dec 11, 2008 at 9:45 PM, Mike Rowe wrote: > Greetings! > > I come to R by way of Matlab. One feature in Matlab I miss is its > "end" keyword. When you put "end" inside an indexing expression, it > is interpreted as the length of the variable along th

[R] The end of Matlab

2008-12-11 Thread Mike Rowe
Greetings! I come to R by way of Matlab. One feature in Matlab I miss is its "end" keyword. When you put "end" inside an indexing expression, it is interpreted as the length of the variable along the dimension being indexed. For example, if the same feature were implemented in R: my.vector[5:e