Re: [R] Extracting data using subset function

2023-02-06 Thread Upananda Pani
Hi Avi,

Thanks a lot. This worked well.

My sincere gratitude to you for teaching me. I am also grateful to
previous forum contributors, who have given me the various dimensions to
think and solve the problem. It has really helped to enhance my
understanding of subsetting function.

Thank you once again to all of you.

Regards,
Upananda Pani

On Mon, Feb 6, 2023 at 4:29 AM  wrote:

> In reading the post again, it sounds like the question is how to create a
> logical condition that translates as 1:N is TRUE. Someone hinted along
> those lines.
>
> So one WAY I might suggest is you construct a logical vector as shown
> below. I give an example of a bunch of 9 primes and you want only the first
> 5.
>
> > vec <- c(1,2,3,5,7,11,13,17, 19)
> > length(vec)
> [1] 9
> > N <- 5
> > choose <- rep(TRUE, N)
> > choose
> [1] TRUE TRUE TRUE TRUE TRUE
> > subset(vec, choose)# will fail as the remaining are recycled or
> assumed to be true
> [1]  1  2  3  5  7 11 13 17 19
> > tot = length(vec)
> > choose <- c(rep(TRUE, N), rep(FALSE, tot - N))
> > choose
> [1]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
> > subset(vec, choose)
> [1] 1 2 3 5 7
>
> The end shows you need to create N Boolean TRUE values and tot-N FALSE to
> make a vector of the same length as the first so everything is indexed.
>
> Does something like this meet your needs?
>
> Realistically, the above technique generalizes to more complex cases
> decently. But sometimes, head(0 and other things I mentioned earlier work
> quite well.
>
>
> -Original Message-----
> From: R-help  On Behalf Of Upananda Pani
> Sent: Sunday, February 5, 2023 2:33 PM
> To: Andrés González Carmona 
> Cc: r-help 
> Subject: Re: [R] Extracting data using subset function
>
> Thank you. It means we can not use the subset function here.
>
> Regards
>
> On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona, 
> wrote:
>
> > From ?subset:
> > Warning
> >
> > This is a convenience function intended for use interactively. For
> > programming it is better to use the standard subsetting functions like
> > [ <http://127.0.0.1:21786/library/base/help/%5B>, and in particular
> > the non-standard evaluation of argument subset can have unanticipated
> > consequences.
> >
> > El 05/02/2023 a las 15:07, Upananda Pani escribió:
> >
> > 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-h...@r-project.org
> > mailing list -- To UNSUBSCRIBE and more,
> > seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r
> > -help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHa
> > Op9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
> > PLEASE do read the posting guide
> > https://urldefense.com/v3/__http://www.R-project.org/posting-guide.htm
> > l__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Q
> > xs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
> > and provide commented, minimal, self-contained, reproducible code.
> >
> > --
> > * Andrés González Carmona *
> >
>
> [[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.
>
>

[[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread avi.e.gross
In reading the post again, it sounds like the question is how to create a 
logical condition that translates as 1:N is TRUE. Someone hinted along those 
lines. 

So one WAY I might suggest is you construct a logical vector as shown below. I 
give an example of a bunch of 9 primes and you want only the first 5.

> vec <- c(1,2,3,5,7,11,13,17, 19)
> length(vec)
[1] 9
> N <- 5
> choose <- rep(TRUE, N)
> choose
[1] TRUE TRUE TRUE TRUE TRUE
> subset(vec, choose)# will fail as the remaining are recycled or 
> assumed to be true
[1]  1  2  3  5  7 11 13 17 19
> tot = length(vec)
> choose <- c(rep(TRUE, N), rep(FALSE, tot - N))
> choose
[1]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
> subset(vec, choose)
[1] 1 2 3 5 7

The end shows you need to create N Boolean TRUE values and tot-N FALSE to make 
a vector of the same length as the first so everything is indexed.

Does something like this meet your needs?

Realistically, the above technique generalizes to more complex cases decently. 
But sometimes, head(0 and other things I mentioned earlier work quite well.


-Original Message-
From: R-help  On Behalf Of Upananda Pani
Sent: Sunday, February 5, 2023 2:33 PM
To: Andrés González Carmona 
Cc: r-help 
Subject: Re: [R] Extracting data using subset function

Thank you. It means we can not use the subset function here.

Regards

On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona,  wrote:

> From ?subset:
> Warning
>
> This is a convenience function intended for use interactively. For 
> programming it is better to use the standard subsetting functions like 
> [ <http://127.0.0.1:21786/library/base/help/%5B>, and in particular 
> the non-standard evaluation of argument subset can have unanticipated 
> consequences.
>
> El 05/02/2023 a las 15:07, Upananda Pani escribió:
>
> 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-h...@r-project.org 
> mailing list -- To UNSUBSCRIBE and more, 
> seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r
> -help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHa
> Op9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
> PLEASE do read the posting guide 
> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.htm
> l__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Q
> xs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
> and provide commented, minimal, self-contained, reproducible code.
>
> --
> * Andrés González Carmona *
>

[[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Rolf Turner


On Sun, 5 Feb 2023 15:13:54 -0500
Duncan Murdoch  wrote:


> 
> Just to build the mountain a little higher, I would use
> 
>subset(p, seq_along(p) <= 20)
> 
> You should generally avoid expressions like "1:length(p)", because
> they don't do what you would expect in the unusual case that p is
> length 0.
> 
> Even in cases where you know p is not length 0, it's a good habit to
> get into so that in the future you don't get surprised.

Aaarrrggghhh.  That was a dumb-dumb on my part.  As Burns said to
Ripley (fortunes::fortune(26)), good catch.

Thanks.

cheers,

Rolf

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Stats. Dep't. phone: +64-9-373-7599 ext. 89622
Home phone: +64-9-480-4619

__
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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Rui Barradas

Às 22:14 de 05/02/2023, Rui Barradas escreveu:

Às 19:33 de 05/02/2023, Upananda Pani escreveu:

Thank you. It means we can not use the subset function here.

Regards

On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona,  
wrote:



 From ?subset:
Warning

This is a convenience function intended for use interactively. For
programming it is better to use the standard subsetting functions like [
, and in particular the
non-standard evaluation of argument subset can have unanticipated
consequences.

El 05/02/2023 a las 15:07, Upananda Pani escribió:

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-h...@r-project.org 
mailing list -- To UNSUBSCRIBE and more, 
seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
PLEASE do read the posting guide 
https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$

and provide commented, minimal, self-contained, reproducible code.

--
* Andrés González Carmona *



[[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.

Hello,

Yes you can:


subset(p, p %in% 1:20)
# [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20


Hope this helps,

Rui Barradas

__
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.

Hello,

But a much more natural the *first* n observations is with function head.


head(p, n = 20)
# [1]  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19


Hope this helps,

Rui Barradas

__
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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Rui Barradas

Às 19:33 de 05/02/2023, Upananda Pani escreveu:

Thank you. It means we can not use the subset function here.

Regards

On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona,  wrote:


 From ?subset:
Warning

This is a convenience function intended for use interactively. For
programming it is better to use the standard subsetting functions like [
, and in particular the
non-standard evaluation of argument subset can have unanticipated
consequences.

El 05/02/2023 a las 15:07, Upananda Pani escribió:

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-h...@r-project.org mailing list 
-- To UNSUBSCRIBE and more, 
seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
PLEASE do read the posting guide 
https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
and provide commented, minimal, self-contained, reproducible code.

--
* Andrés González Carmona *



[[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.

Hello,

Yes you can:


subset(p, p %in% 1:20)
# [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20


Hope this helps,

Rui Barradas

__
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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Uwe Ligges
I tend not to teach subset() as indexing is needed anyway and hence 
subset() is just an extra level of cpmplexity that is not needed.

Also note what ?subset warns about.

Best,
Uwe Ligges


On 05.02.2023 22:12, avi.e.gr...@gmail.com wrote:

A major question is why you ask how to use the subset function rather than 
asking how to get your job done.

As you note, the simple way to get the first N items is to use indexing. If you 
absolutely positively insist on using subset, place your data into something 
like a data.frame and add a column and use that.

Say you have N items, so that length() or nrow() return N. You can add a column called index 
whose entries are 1:N and do your subset to get all rows where the condition is "index 
<= N" or something like that.

If you want just the first N (not N at a time in several tries) simply used 
head(data, N) and that gets you the first N.

And if you are interested in learning other packages like dplyr in the tidyverse, 
it has oodles of ways to select based on row numbers. One example is top_n(...) 
and another is slice(first, last)  and in some contexts such as the filter() 
function, there is a sort of internal function you can use called n() that 
contains the index of the entry within any grouping so filter(mydata, n() <= 
20) might get what you want.

Note that the above requires care as some things work on vectors and others 
assume a data.frame, albeit you can make a data.frame containing a single 
vector.


-Original Message-
From: R-help  On Behalf Of Upananda Pani
Sent: Sunday, February 5, 2023 2:33 PM
To: Andrés González Carmona 
Cc: r-help 
Subject: Re: [R] Extracting data using subset function

Thank you. It means we can not use the subset function here.

Regards

On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona,  wrote:


 From ?subset:
Warning

This is a convenience function intended for use interactively. For
programming it is better to use the standard subsetting functions like
[ <http://127.0.0.1:21786/library/base/help/%5B>, and in particular
the non-standard evaluation of argument subset can have unanticipated
consequences.

El 05/02/2023 a las 15:07, Upananda Pani escribió:

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-h...@r-project.org
mailing list -- To UNSUBSCRIBE and more,
seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r
-help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHa
Op9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
PLEASE do read the posting guide
https://urldefense.com/v3/__http://www.R-project.org/posting-guide.htm
l__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Q
xs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
and provide commented, minimal, self-contained, reproducible code.

--
* Andrés González Carmona *



[[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.


__
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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Jim Lemon
Hi Upananda,
As a couple of respondents noted, you only need the logical statement,
not subset().

You did "frame the logical condition" in your example, for if you use
the extraction operator "[" this will work:
subset(p,(1:length(p)) <= 20)
as Jeff already pointed out. Obviously it is easier to write:
p[(1:length(p)) <= 20]

Let's say you want to select the odd numbers in p:
p<-1:10
as.logical(p%%2)
[1]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
p[as.logical(p%%2)]
[1] 1 3 5 7 9
The as.logical() has to be included as the extractor function tries
use integers as indices

So the problem is really to reduce your selection criteria to a vector
of TRUER/FALSE values.

Jim

On Mon, Feb 6, 2023 at 1:07 AM Upananda Pani  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@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.


Re: [R] Extracting data using subset function

2023-02-05 Thread avi.e.gross
A major question is why you ask how to use the subset function rather than 
asking how to get your job done.

As you note, the simple way to get the first N items is to use indexing. If you 
absolutely positively insist on using subset, place your data into something 
like a data.frame and add a column and use that.

Say you have N items, so that length() or nrow() return N. You can add a column 
called index whose entries are 1:N and do your subset to get all rows where the 
condition is "index <= N" or something like that. 

If you want just the first N (not N at a time in several tries) simply used 
head(data, N) and that gets you the first N.

And if you are interested in learning other packages like dplyr in the 
tidyverse, it has oodles of ways to select based on row numbers. One example is 
top_n(...) and another is slice(first, last)  and in some contexts such as the 
filter() function, there is a sort of internal function you can use called n() 
that contains the index of the entry within any grouping so filter(mydata, n() 
<= 20) might get what you want.

Note that the above requires care as some things work on vectors and others 
assume a data.frame, albeit you can make a data.frame containing a single 
vector.


-Original Message-
From: R-help  On Behalf Of Upananda Pani
Sent: Sunday, February 5, 2023 2:33 PM
To: Andrés González Carmona 
Cc: r-help 
Subject: Re: [R] Extracting data using subset function

Thank you. It means we can not use the subset function here.

Regards

On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona,  wrote:

> From ?subset:
> Warning
>
> This is a convenience function intended for use interactively. For 
> programming it is better to use the standard subsetting functions like 
> [ <http://127.0.0.1:21786/library/base/help/%5B>, and in particular 
> the non-standard evaluation of argument subset can have unanticipated 
> consequences.
>
> El 05/02/2023 a las 15:07, Upananda Pani escribió:
>
> 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-h...@r-project.org 
> mailing list -- To UNSUBSCRIBE and more, 
> seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r
> -help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHa
> Op9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
> PLEASE do read the posting guide 
> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.htm
> l__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Q
> xs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
> and provide commented, minimal, self-contained, reproducible code.
>
> --
> * Andrés González Carmona *
>

[[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Jeff Newmiller
I will not (re-)define the basic terms used in describing how R is used... do 
read [1] for that.

[1] 
https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Writing-your-own-functions,
 also via RShowDoc("R-intro"), in particular contrast section 1.5 vs section 10.

On February 5, 2023 12:10:46 PM PST, Upananda Pani  
wrote:
>Hi Jeff,
>
>Thanks for your reply. What do you exactly mean by "interactively"?  Would
>you please give me an example?
>Upananda
>
>On Mon, Feb 6, 2023 at 1:27 AM Jeff Newmiller 
>wrote:
>
>> No, it means what it says: it is best used interactively rather than in
>> functions. That is not saying you cannot use it... merely that you should
>> probably use it interactively.
>>
>> The fact is, though, that integer indexing is much simpler and clearer for
>> your particular example than subset is.
>>
>> q <- p[1:20]
>> q2 <- subset( p, 1:100 <= 20) # 1:100 are positions
>>
>> On February 5, 2023 11:33:16 AM PST, Upananda Pani <
>> upananda.p...@gmail.com> wrote:
>> >Thank you. It means we can not use the subset function here.
>> >
>> >Regards
>> >
>> >On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona, 
>> wrote:
>> >
>> >> From ?subset:
>> >> Warning
>> >>
>> >> This is a convenience function intended for use interactively. For
>> >> programming it is better to use the standard subsetting functions like [
>> >> , and in particular the
>> >> non-standard evaluation of argument subset can have unanticipated
>> >> consequences.
>> >>
>> >> El 05/02/2023 a las 15:07, Upananda Pani escribió:
>> >>
>> >> 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-h...@r-project.org
>> mailing list -- To UNSUBSCRIBE and more, seehttps://
>> urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
>> >> PLEASE do read the posting guide
>> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
>> >> and provide commented, minimal, self-contained, reproducible code.
>> >>
>> >> --
>> >> * Andrés González Carmona *
>> >>
>> >
>> >   [[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.
>>
>> --
>> Sent from my phone. Please excuse my brevity.
>>

-- 
Sent from my phone. Please excuse my brevity.

__
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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Upananda Pani
Hi Rolf,

Thank you so much. I was just curious to know that. I am glad that i got
the input from all of you.

I am grateful to you  for clarifying.

With sincere gratitude,
Upananda

On Mon, Feb 6, 2023 at 1:29 AM Rolf Turner  wrote:

> On Sun, 5 Feb 2023 19:37:03 +0530
> Upananda Pani  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.
>
> I think that you are manufacturing an unnecessary difficulty.  If you
> want the first 20 entries of p, use p[1:20]!!!
>
> However, if you obdurately *insist* on using subset() you could do
>
> subset(p,(1:length(p)) <= 20)
>
> This works, but makes a mountain out of a molehill.
>
> cheers,
>
> Rolf Turner
>
> --
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Stats. Dep't. phone: +64-9-373-7599 ext. 89622
> Home phone: +64-9-480-4619
>
>

[[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Upananda Pani
Hi Jeff,

Thanks for your reply. What do you exactly mean by "interactively"?  Would
you please give me an example?
Upananda

On Mon, Feb 6, 2023 at 1:27 AM Jeff Newmiller 
wrote:

> No, it means what it says: it is best used interactively rather than in
> functions. That is not saying you cannot use it... merely that you should
> probably use it interactively.
>
> The fact is, though, that integer indexing is much simpler and clearer for
> your particular example than subset is.
>
> q <- p[1:20]
> q2 <- subset( p, 1:100 <= 20) # 1:100 are positions
>
> On February 5, 2023 11:33:16 AM PST, Upananda Pani <
> upananda.p...@gmail.com> wrote:
> >Thank you. It means we can not use the subset function here.
> >
> >Regards
> >
> >On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona, 
> wrote:
> >
> >> From ?subset:
> >> Warning
> >>
> >> This is a convenience function intended for use interactively. For
> >> programming it is better to use the standard subsetting functions like [
> >> , and in particular the
> >> non-standard evaluation of argument subset can have unanticipated
> >> consequences.
> >>
> >> El 05/02/2023 a las 15:07, Upananda Pani escribió:
> >>
> >> 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-h...@r-project.org
> mailing list -- To UNSUBSCRIBE and more, seehttps://
> urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
> >> PLEASE do read the posting guide
> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >> --
> >> * Andrés González Carmona *
> >>
> >
> >   [[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.
>
> --
> Sent from my phone. Please excuse my brevity.
>

[[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Duncan Murdoch

On 05/02/2023 2:59 p.m., Rolf Turner wrote:

On Sun, 5 Feb 2023 19:37:03 +0530
Upananda Pani  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.


I think that you are manufacturing an unnecessary difficulty.  If you
want the first 20 entries of p, use p[1:20]!!!

However, if you obdurately *insist* on using subset() you could do

 subset(p,(1:length(p)) <= 20)

This works, but makes a mountain out of a molehill.


Just to build the mountain a little higher, I would use

  subset(p, seq_along(p) <= 20)

You should generally avoid expressions like "1:length(p)", because they 
don't do what you would expect in the unusual case that p is length 0.


Even in cases where you know p is not length 0, it's a good habit to get 
into so that in the future you don't get surprised.


Duncan Murdoch

__
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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Rolf Turner
On Sun, 5 Feb 2023 19:37:03 +0530
Upananda Pani  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.

I think that you are manufacturing an unnecessary difficulty.  If you
want the first 20 entries of p, use p[1:20]!!!

However, if you obdurately *insist* on using subset() you could do

subset(p,(1:length(p)) <= 20)

This works, but makes a mountain out of a molehill.

cheers,

Rolf Turner

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Stats. Dep't. phone: +64-9-373-7599 ext. 89622
Home phone: +64-9-480-4619

__
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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Jeff Newmiller
No, it means what it says: it is best used interactively rather than in 
functions. That is not saying you cannot use it... merely that you should 
probably use it interactively.

The fact is, though, that integer indexing is much simpler and clearer for your 
particular example than subset is.

q <- p[1:20]
q2 <- subset( p, 1:100 <= 20) # 1:100 are positions

On February 5, 2023 11:33:16 AM PST, Upananda Pani  
wrote:
>Thank you. It means we can not use the subset function here.
>
>Regards
>
>On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona,  wrote:
>
>> From ?subset:
>> Warning
>>
>> This is a convenience function intended for use interactively. For
>> programming it is better to use the standard subsetting functions like [
>> , and in particular the
>> non-standard evaluation of argument subset can have unanticipated
>> consequences.
>>
>> El 05/02/2023 a las 15:07, Upananda Pani escribió:
>>
>> 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-h...@r-project.org mailing 
>> list -- To UNSUBSCRIBE and more, 
>> seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
>> PLEASE do read the posting guide 
>> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
>> and provide commented, minimal, self-contained, reproducible code.
>>
>> --
>> * Andrés González Carmona *
>>
>
>   [[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.

-- 
Sent from my phone. Please excuse my brevity.

__
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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Upananda Pani
Thank you. It means we can not use the subset function here.

Regards

On Mon, 6 Feb, 2023, 00:53 Andrés González Carmona,  wrote:

> From ?subset:
> Warning
>
> This is a convenience function intended for use interactively. For
> programming it is better to use the standard subsetting functions like [
> , and in particular the
> non-standard evaluation of argument subset can have unanticipated
> consequences.
>
> El 05/02/2023 a las 15:07, Upananda Pani escribió:
>
> 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-h...@r-project.org mailing 
> list -- To UNSUBSCRIBE and more, 
> seehttps://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkynoP5dEA$
> PLEASE do read the posting guide 
> https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!D9dNQwwGXtA!SLdwTGqSfhwUo4CfbUJFeL7hETw64hOG8MQ0FK_o5YdnvVHaOp9Qxs4D7d5e10hj3YQ8EuaFc8qbnkwuss43hA$
> and provide commented, minimal, self-contained, reproducible code.
>
> --
> * Andrés González Carmona *
>

[[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Upananda Pani
How you have defined z1?

On Mon, 6 Feb, 2023, 00:14 粕谷英一,  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 :
> >
> > 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, 
> > 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.p...@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@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.
> > >
> >
> > [[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.
>

[[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread 粕谷英一
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 :
>
> 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, 
> 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 
> > 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@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.
> >
>
> [[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Upananda Pani
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, 
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 
> 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@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.
>

[[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.


Re: [R] Extracting data using subset function

2023-02-05 Thread Chris Ryan via R-help
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  
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@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.


[R] Extracting data using subset function

2023-02-05 Thread Upananda Pani
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@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.