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]]
Have you spent time with any R tutorials? Your queries are really elementary, and this list really cannot serve as a tutorial service. See the Posting Guide linked below for what help you can expect here ... and how to post queries that will get that help. Cheers, Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Nov 1, 2021 at 12:49 PM Alice <alice at 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 at 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. >[[alternative HTML version deleted]]
x[ x > 2] On Mon, Nov 1, 2021 at 9:49 PM Alice <alice at 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 at 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.
Hi Alice, I can see from your two questions that your English is a bit shaky. This is not a criticism, I couldn't speak Chinese to save my life. I looked around for a Chinese R help mailing list and couldn't find one. Perhaps someone else knows of one. Not only would it make your life easier at the moment, but it may help you learning R jargon in English. Jim On Tue, Nov 2, 2021 at 6:49 AM Alice <alice at 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 at 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.