x[ x > 2]

On Mon, Nov 1, 2021 at 9:49 PM Alice <al...@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@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.

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

Reply via email to