[R] How to slice the array?

Eric Berger er|cjberger @end|ng |rom gm@||@com
Mon Nov 1 21:16:32 CET 2021


x[ x > 2]

On Mon, Nov 1, 2021 at 9:49 PM Alice <alice using coakmail.com> wrote:
>
> How to slice the array with the condition?
> For example, in perl I can get the elements greater than 2.
>
> $ perl -le '@x=(1,2,3,4,5);@y=grep {$_>2} @x;print "@y"'
>
> 3 4 5
>
>
> in R I know which(x>2), but it will return the indexes instead of an array.
>
>
> Thanks again.
>
>
> Alice
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list