[R] The end of Matlab

Gabor Grothendieck ggrothendieck at gmail.com
Fri Dec 12 18:26:46 CET 2008


On Fri, Dec 12, 2008 at 12:11 PM, Vitalie Spinu <vitosmail at rambler.ru> wrote:
> On Fri, 12 Dec 2008 17:38:13 +0100, hadley wickham <h.wickham at gmail.com>
> 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)) observations.   An iterator version of rev()
>> would also be handy.
>>
>> Maybe selector would be a better name than iterator though, as these
>> don't have the same feel as iterators in other languages.
>
> That is really something!! Real high level language!!
> "Selectors" could depend on named variables in data frame as well:
>
> mtcars[sel(cyl>3)&last(5)]
> mtcars[sel(cyl>3)&boot(80%)]
>
> or may be just
> mtcars[cyl>3&last(20)]
>

You can do this (and quite a bit more) in data.table:

> library(data.table)
> mtcars.dt <- as.data.table(mtcars)
> tail(mtcars.dt[cyl < 5], 4)
      mpg cyl  disp  hp drat    wt qsec vs am gear carb
[1,] 27.3   4  79.0  66 4.08 1.935 18.9  1  1    4    1
[2,] 26.0   4 120.3  91 4.43 2.140 16.7  0  1    5    2
[3,] 30.4   4  95.1 113 3.77 1.513 16.9  1  1    5    2
[4,] 21.4   4 121.0 109 4.11 2.780 18.6  1  1    4    2



More information about the R-help mailing list