Re: [R] Extracting data using subset function

2023-02-06 Thread Upananda Pani
gt; 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:3

Re: [R] Extracting data using subset function

2023-02-05 Thread avi.e.gross
a 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: >

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

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

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

Re: [R] Extracting data using subset function

2023-02-05 Thread Uwe Ligges
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, 20

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

Re: [R] Extracting data using subset function

2023-02-05 Thread avi.e.gross
, 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 no

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

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: >

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

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

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

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

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

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

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.

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

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

[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