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

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

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

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

[ESS] A debate on progress: WAS build problem

2023-02-05 Thread Sparapani, Rodney via ESS-help
Hi Dirk and ESS-help: It is a slow nice day on ESS-help so I will entertain a debate. Nice to see that my old friend Dirk has not frozen solid. The thermometer has recently explored some rare territory. However, I have to respectfully disagree. I didn�t feel such a commitment to progress when I

Re: [ESS] build problem

2023-02-05 Thread Dirk Eddelbuettel via ESS-help
On 5 February 2023 at 15:01, Sparapani, Rodney via ESS-help wrote: | I don�t have 28 on this machine. I am using 26 since there is not much | benefit upgrading. I am really sorry but I cannot let this stand. It is too close to FUD. As a general rule, newer *is* better. Features get added, bugs

Re: [ESS] build problem

2023-02-05 Thread Sparapani, Rodney via ESS-help
Hi Tom: I don�t have 28 on this machine. I am using 26 since there is not much benefit upgrading. But, anyways, ess-gretl.el appears to offer Gretl support. Since you are interested in R, just delete that file. For me, the build goes fine without it. Thanks -- Rodney Sparapani, Associate

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