[R] Extracting data using subset function

Upananda Pani up@n@nd@@p@n| @end|ng |rom gm@||@com
Sun Feb 5 20:32:24 CET 2023


How you have defined z1?

On Mon, 6 Feb, 2023, 00:14 粕谷英一, <ekasuscb using kyushu-u.org> wrote:

> Do you mean something like the following?  Here the first elements are
> selected by subset function.
>
> > x1
> [1] 9 8 7 6 5 4 3
> > z1
> [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
> > subset(x1,z1)
> [1] 9 8 7
>
> 2023年2月6日(月) 3:34 Upananda Pani <upananda.pani using gmail.com>:
> >
> > No i am teaching Econometrics and learning R. I am not a student.
> >
> > Thank you
> > Upananda
> >
> > On Sun, 5 Feb, 2023, 19:51 Chris Ryan via R-help, <r-help using r-project.org>
> > wrote:
> >
> > > Is this a homework problem?
> > >
> > > --Chris Ryan
> > > --
> > > Sent from my Android device with K-9 Mail. Please excuse my brevity.
> > >
> > > On February 5, 2023 9:07:03 AM EST, Upananda Pani <
> upananda.pani using gmail.com>
> > > wrote:
> > > >Dear All,
> > > >
> > > >I want to create a vector p and extract first 20 observations using
> subset
> > > >function based on logical condition.
> > > >
> > > >My code is below
> > > >
> > > >p <- 0:100
> > > >
> > > >I know i can extract the first 20 observations using the following
> > > command.
> > > >
> > > >q <- p[1:20]
> > > >
> > > >But I want to extract the first 20 observations using subset function
> > > which
> > > >requires a logical condition. I am not able to frame the logical
> > > condition.
> > > >
> > > >The code should be
> > > >
> > > >q <- subset(p, logical condition)
> > > >
> > > >I am not able to do it. Please let me know what you think.
> > > >
> > > >Best regards,
> > > >Upananda
> > > >
> > > >       [[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.
> > >
> > > ______________________________________________
> > > 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.
> > >
> >
> >         [[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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list