Re: [R] Matlab end operator

From: AA <aa2007r_at_gmail.com>
Date: Wed, 27 Jun 2007 17:18:04 -0400

Hi Markus, Christophe

I also use both matlab and R.
I agree with Christophe: you can define the 'end' functionality by nrow or length
also have a look at the following link that may be useful. http://mathesaurus.sourceforge.net/octave-r.html good luck
AA.
----- Original Message -----
From: "Christophe Pallier" <christophe_at_pallier.org> To: "Markus Loecher" <loecher_at_eden.rutgers.edu> Cc: <r-help_at_stat.math.ethz.ch>
Sent: Wednesday, June 27, 2007 2:43 PM
Subject: Re: [R] Matlab end operator

> Hello Markus,
>
> On 6/27/07, Markus Loecher <loecher_at_eden.rutgers.edu> wrote:
>>
>> Dear list members,
>> I use both R and Matlab and find that each has its own strengths. Matlab
>> definitely has the edge when it comes to the interactivity of its graphs.
>
>
> I also use both. R definitely has the edge when it comes to do perform
> statistical data analyses :)
> (and also when you consider the price...)
>
> In addition I find the little operator end extremely useful in indexing
>> arrays. (as in x(1:end,) )
>
>
> You mean 'x(1:end,1:end)' or 'x(:,:)' (':' is equivalent to "1:end")
>
> When I go from R to Matlab, I tend to forget to type the ':' ("a[,2]" in R
> is "a(:,2)" in Matlab.)
>
> The interest of 'end' is clearer when the starting index is larger than 1
> as
> in, e.g., 'x(2:end)'
>
> Yet note that in R, you can use negative indexes:
>
> x[-1] is the R equivalent of Matlab's x(2:end)
>
> x[-(1:(n-1))] is equivalent to x(n:end)
>
>
> I agree that R syntax may be a bit less "elegant" in this particular
> situation (but try to write the equivalent of a[-2,] in Matlab)
> Personally, I would stick to "x[n:length(x)]" (or "a[n:nrow(a),]" for a
> matrix). Anyway this kind of code would probably appear inside a loop and
> I
> would put the numbers of rows or columns in variables if there are needed
> more than once.
>
> Best,
>
> --
> Christophe Pallier
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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_at_stat.math.ethz.ch 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. Received on Wed 27 Jun 2007 - 22:03:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Jun 2007 - 23:32:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.