Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-26 Thread Duncan Murdoch
If a uniform sample is needed, it's fairly easy to turn my solution into a rejection sampler that is uniform across the region satisfying the constraints. It has an acceptance rate that is bounded below by something like 1/factorial(dim-1), e.g. 1/6 in 4 dimensions. Duncan Murdoch On 2025-04-

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-26 Thread Bert Gunter
Yes, thanks. I got my algebra/constraints wrong. ... Sigh... Unfortunatey, this seems to make things yet more difficult. -- Bert "An educated person is one who can entertain new ideas, entertain others, and entertain herself." On Sat, Apr 26, 2025 at 10:01 AM Duncan Murdoch wrote: > On 2025

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-26 Thread Duncan Murdoch
And I missed copying one line: sums <- rowSums(x) should come between the calculations of x and x0. Duncan Murdoch On 2025-04-26 1:01 p.m., Duncan Murdoch wrote: On 2025-04-24 3:25 p.m., Bert Gunter wrote: Folks: Unless my wee old brain errs (always a danger), uniform sampling from an n-vec

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-26 Thread Duncan Murdoch
On 2025-04-24 3:25 p.m., Bert Gunter wrote: Folks: Unless my wee old brain errs (always a danger), uniform sampling from an n-vector for which 0 <= ai <= xi <= bi and SUM(xi) = k, a constant, where to ensure that the constraints are consistent (and nontrivial), SUM(ai)< k and SUM(bi) > k, is a

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-24 Thread Duncan Murdoch
BTW, my function could be a little more efficient: it can only possibly have lowlimit > highlimit on the first coordinate, so that test could come out of the loop. Duncan Murdoch On 2025-04-24 4:05 p.m., Duncan Murdoch wrote: On 2025-04-24 1:33 p.m., Brian Smith wrote: Hi Rui, This code

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-24 Thread Duncan Murdoch
On 2025-04-24 1:33 p.m., Brian Smith wrote: Hi Rui, This code is able to generate absolutely correct random sample vector based on the applicable constraints. I have one question though. If I understood the R code correctly then, the first element is drawing random number from Uniform distribu

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-24 Thread Bert Gunter
Folks: Unless my wee old brain errs (always a danger), uniform sampling from an n-vector for which 0 <= ai <= xi <= bi and SUM(xi) = k, a constant, where to ensure that the constraints are consistent (and nontrivial), SUM(ai)< k and SUM(bi) > k, is a simple linear transformation (details left to

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-24 Thread Brian Smith
Hi Rui, This code is able to generate absolutely correct random sample vector based on the applicable constraints. I have one question though. If I understood the R code correctly then, the first element is drawing random number from Uniform distribution unconditionally, however drawing of sampl

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-22 Thread Rui Barradas
Hello, Here are your tests and the random numbers' histograms. one_vec <- function(a, b, s) { repeat{ repeat{ u <- runif(1, a[1], b[1]) if(s - u > 0) break } v <- s - u if(a[2] < v && v < b[2]) break } c(u, v) } gen_mat <- function(m, a, b, s) { replicate(m,

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-22 Thread Rui Barradas
Hello, Inline. Às 17:55 de 22/04/2025, Brian Smith escreveu: i.e. we should have all elements of Reduce("+", res) should be equal to s = 0.05528650577311 My assertion is that it is not happing here. You are right, that's not what is happening. The output is n vectors of 2 elements each. I

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-22 Thread Brian Smith
i.e. we should have all elements of Reduce("+", res) should be equal to s = 0.05528650577311 My assertion is that it is not happing here. On Tue, 22 Apr 2025 at 22:20, Brian Smith wrote: > > Hi Rui, > > Thanks for the explanation. > > But in this case, are we looking at the correct solution a

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-22 Thread Brian Smith
Hi Rui, Thanks for the explanation. But in this case, are we looking at the correct solution at all? My goal is to generate random vector where: 1) the first element is bounded by (a[1], b[1]) and second element is bounded by (a[2], b[2]) 2) sum of the element is s According to the outcome, The

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-22 Thread Rui Barradas
Às 12:39 de 22/04/2025, Brian Smith escreveu: Hi Rui, Many thanks for your time and insight. However, I am not sure if I could understand the code. Below is what I tried based on your code library(Surrogate) a <- c(0.015, 0.005) b <- c(0.070, 0.045) set.seed(2025) res <- mapply(\(a, b, s, n, m

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-22 Thread Brian Smith
Hi Rui, Many thanks for your time and insight. However, I am not sure if I could understand the code. Below is what I tried based on your code library(Surrogate) a <- c(0.015, 0.005) b <- c(0.070, 0.045) set.seed(2025) res <- mapply(\(a, b, s, n, m) RandVec(a, b, s, n, m), MoreArg

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-21 Thread Rui Barradas
Hello, Inline. Às 16:08 de 21/04/2025, Rui Barradas escreveu: Às 15:27 de 21/04/2025, Brian Smith escreveu: Hi, There is a function called RandVec in the package Surrogate which can generate andom vectors (continuous number) with a fixed sum The help page of this function states that: a Th

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-21 Thread Rui Barradas
Às 15:27 de 21/04/2025, Brian Smith escreveu: Hi, There is a function called RandVec in the package Surrogate which can generate andom vectors (continuous number) with a fixed sum The help page of this function states that: a The function RandVec generates an n by m matrix x. Each of the m co

Re: [R] Generate random vectors (continuous number) with a fixed sum

2025-04-21 Thread Eric Berger
RandVec expects both a and b to be single numbers, not numeric vectors of length > 1. You could create pairs of (a,b) values and cycle through them. There are many ways to do that. Here is one example. (Note that using a=0.1, b=.2, s=1, n=2 is impossible to achieve, since two numbers bounded above

[R] Generate random vectors (continuous number) with a fixed sum

2025-04-21 Thread Brian Smith
Hi, There is a function called RandVec in the package Surrogate which can generate andom vectors (continuous number) with a fixed sum The help page of this function states that: a The function RandVec generates an n by m matrix x. Each of the m columns contain n random values lying in the inter

Re: [R] generate distribution based on summary data and add random noise

2022-02-03 Thread Bert Gunter
subject to the legally > binding disclaimer: https://www.precheza.cz/en/01-disclaimer/ > > From: Bert Gunter > Sent: Thursday, February 3, 2022 5:10 PM > To: PIKAL Petr > Cc: R-help > Subject: Re: [R] generate distribution based on summary data and add > random noise > >

Re: [R] generate random numeric

2021-10-29 Thread Ken Peng
That's all right. Thanks. On Sat, Oct 30, 2021 at 12:29 AM Marc Schwartz wrote: > Ken Peng wrote on 10/29/21 2:39 AM: > > I saw runif(1) can generate a random num, is this the true random? > > > >> runif(1) > > [1] 0.8945383 > > > > What's the other better method? > > > > Thank you. > > > Hi, >

Re: [R] generate random numeric

2021-10-29 Thread Marc Schwartz via R-help
Ken Peng wrote on 10/29/21 2:39 AM: I saw runif(1) can generate a random num, is this the true random? runif(1) [1] 0.8945383 What's the other better method? Thank you. Hi, You do not indicate your use case, and that can be important. The numbers generated by R's default RNGs are "pseudo

Re: [R] generate random numeric

2021-10-29 Thread Jeff Newmiller
It is difficult to do "truly random" number generation with computers, but fortunately number sequences that appear random but progress consistently from an initial seed value (?set.seed) are actually much more useful for analysis purposes than true randomness is. On October 28, 2021 11:39:07 P

Re: [R] generate random numeric

2021-10-28 Thread Andrew Simmons
It might not be random, depending upon a seed being used (usually by set.seed or RNGkind). However, it's the best method for generating a random number within a specified range without weights. If you want weights, there are many other random number generation functions, most notably rnorm. You c

[R] generate random numeric

2021-10-28 Thread Ken Peng
I saw runif(1) can generate a random num, is this the true random? > runif(1) [1] 0.8945383 What's the other better method? Thank you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see h

Re: [R] generate average frame from different data frames

2021-10-24 Thread Luigi Marongiu
Thanks for the tip! I'll check it out. On Sun, Oct 24, 2021 at 8:07 AM Jim Lemon wrote: > > Hi Luigi, > In that case you will want a binomial confidence interval. > > Jim > > On Sun, Oct 24, 2021 at 4:39 PM Luigi Marongiu > wrote: > > > > Thank you. Sorry for the fuzziness of the question but I

Re: [R] generate average frame from different data frames

2021-10-23 Thread Jim Lemon
Hi Luigi, In that case you will want a binomial confidence interval. Jim On Sun, Oct 24, 2021 at 4:39 PM Luigi Marongiu wrote: > > Thank you. Sorry for the fuzziness of the question but I find it > difficult to give a proper definition of the problem. I have given a > graphical rendering on this

Re: [R] generate average frame from different data frames

2021-10-23 Thread Luigi Marongiu
Thank you. Sorry for the fuzziness of the question but I find it difficult to give a proper definition of the problem. I have given a graphical rendering on this post https://www.researchgate.net/post/How_to_find_95_CI_of_a_matrix_of_classification_data As you can see in the figure, there are dots

Re: [R] generate average frame from different data frames

2021-10-23 Thread Jim Lemon
Hi Luigi, I may be missing the point, but: matrix((z1+z2+z3)/3,ncol=10) gives you the mean rating for each item, and depending upon what distribution you choose, the confidence intervals could be calculated in much the same way. Jim On Sun, Oct 24, 2021 at 7:16 AM Luigi Marongiu wrote: > > Hel

[R] generate average frame from different data frames

2021-10-23 Thread Luigi Marongiu
Hello, I have a series of classifications of the same data. I saved this classification in a single dataframe (but it could be a list). X and Y are the variable and Z is the classification by three raters. `I` is the individual identifier of each entry: ``` z1 = c(0,0,0,0,0,1,0,0,0,2, 0,1,1,1,0,0,0

Re: [R] Generate oauth token using HTTR package in R

2021-08-03 Thread Mark Fowler
, but I do not know if it still is. Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10 From: Lac Will<mailto:outlook_789d32266f1fd...@outlook.com> Sent: Tuesday, August 3, 2021 4:10 AM To: r-help@r-project.org<mailto:r-help@r-project.org> Subject: [R] Ge

[R] Generate oauth token using HTTR package in R

2021-08-03 Thread Lac Will
Novice attempting R, as displayed below, to obtain an oauth token using HTTR package in R and have a status code of 401. Any insight as to the cause of this error and a resolution? Thanks in advance. # Status: 401 library(httr) base64_value <- "123456789=" response16 <- httr::POST

Re: [R] Generate Range of Correlations Matrix Bernoulli

2018-12-08 Thread إيمان إسماعيل محمد
Thank you for the clarification. ‫في السبت، 8 ديسمبر 2018 في 10:13 م تمت كتابة ما يلي بواسطة ‪Bert Gunter‬‏ <‪bgunter.4...@gmail.com‬‏>:‬ > Unless you are sending a private message, always include the list (which I > have cc'ed) in your reply, because, as here, individuals do not do private > con

Re: [R] Generate Range of Correlations Matrix Bernoulli

2018-12-08 Thread Bert Gunter
Unless you are sending a private message, always include the list (which I have cc'ed) in your reply, because, as here, individuals do not do private consulting and may be unwilling or unable to provide the help you seek. Bert Gunter ‪On Sat, Dec 8, 2018 at 10:33 AM ‫إيمان إسماعيل محمد‬‎ < eman

Re: [R] Generate Range of Correlations Matrix Bernoulli

2018-12-08 Thread Bert Gunter
I have no idea why your post was "rejected," nor even quite what you mean by that. But I believe your post may not receive any replies because you have failed to follow the posting guide linked below. I find it incomprehensible, but maybe others will be able to understand what you want. It may also

[R] Generate Range of Correlations Matrix Bernoulli

2018-12-08 Thread إيمان إسماعيل محمد
Hi all, I was wondering how can I construct range of correlations matrix that cover all space from dependent Multivariate Bernoulli (known Marginal Probabilities but unknown correlations) I have P's for every variable but unknown correlation between each pair I want to try range of applicable corre

Re: [R] Generate N random numbers with a given probability and condition

2018-07-12 Thread David Winsemius
> On Jul 12, 2018, at 12:44 AM, Göran Broström wrote: > > "Acceptance–Rejection Sampling from the Conditional Distribution of > Independent Discrete Random Variables, given their Sum", Statistics 34, pages > 247-257 Dear Go:ran; I'm fully retired with no subscriber academic library that I c

Re: [R] Generate N random numbers with a given probability and condition

2018-07-12 Thread Göran Broström
On 2018-07-05 00:21, Nelly Reduan wrote: Dear all, I would like to generate N random numbers with a given probability and condition but I'm not sure how to do this. For example, I have N = 20 and the vector from which to choose is seq(0, 10, 1). I have tested: x <- sample(seq(0, 10, 1), 20

Re: [R] Generate N random numbers with a given probability and condition

2018-07-11 Thread Duncan Murdoch
On 04/07/2018 6:21 PM, Nelly Reduan wrote: Dear all, I would like to generate N random numbers with a given probability and condition but I'm not sure how to do this. For example, I have N = 20 and the vector from which to choose is seq(0, 10, 1). I have tested: x <- sample(seq(0, 10, 1), 20,

Re: [R] Generate N random numbers with a given probability and condition

2018-07-11 Thread Jim Lemon
t; ____ > De : Jim Lemon > Envoyé : mardi 10 juillet 2018 17:44:13 > À : Nelly Reduan > Objet : Re: [R] Generate N random numbers with a given probability and > condition > > Hi Nell, > I may not have the right idea about this, but I think you

Re: [R] Generate N random numbers with a given probability and condition

2018-07-11 Thread Nelly Reduan
lements of a vector rather than to permute a vector ? Many thanks for your time. Have a nice day Nell De : Jim Lemon Envoyé : mardi 10 juillet 2018 17:44:13 À : Nelly Reduan Objet : Re: [R] Generate N random numbers with a given probability and condition Hi N

Re: [R] Generate N random numbers with a given probability and condition

2018-07-10 Thread Bert Gunter
__ > De : Rolf Turner > Envoyé : mercredi 4 juillet 2018 16:11:11 > À : Nelly Reduan > Cc : r-help@r-project.org > Objet : Re: [R] Generate N random numbers with a given probability and > condition > > > On 05/07/18 10:21, Nelly Reduan wrote: &g

Re: [R] Generate N random numbers with a given probability and condition

2018-07-10 Thread Jim Lemon
bility, I would like to generate N random positive > integers that sum to M and the integers would be selected from a uniform > distribution. > > > Many thanks for your time > > Nell > > > > De : Rolf Turner > Envoyé : mercredi 4

Re: [R] Generate N random numbers with a given probability and condition

2018-07-10 Thread Nelly Reduan
integers that sum to M and the integers would be selected from a uniform distribution. Many thanks for your time Nell De : Rolf Turner Envoyé : mercredi 4 juillet 2018 16:11:11 À : Nelly Reduan Cc : r-help@r-project.org Objet : Re: [R] Generate N random

Re: [R] Generate random Bernoulli draws

2018-07-06 Thread Marino David
Hi Chuck and all, Thanks for your response. It is really helpful for me. David 2018-07-07 7:30 GMT+08:00 Berry, Charles : > Sorry about the last incomplete post. Accidentally hit send. > > Meant to say that I was hoping that a correct, but obscure response from > me would motivate David to ste

Re: [R] Generate random Bernoulli draws

2018-07-06 Thread Berry, Charles
Sorry about the last incomplete post. Accidentally hit send. Meant to say that I was hoping that a correct, but obscure response from me would motivate David to step back and think about his problem long enough to see that it has an easy solution. Sorry if that was out-of-line. Chuck > On Ju

Re: [R] Generate random Bernoulli draws

2018-07-06 Thread Berry, Charles
> On Jul 6, 2018, at 3:31 PM, Duncan Murdoch wrote: > > On 06/07/2018 1:18 PM, Berry, Charles wrote: >> A liitle math goes along way. See below. >>> On Jul 5, 2018, at 10:35 PM, Marino David wrote: >>> >>> Dear Bert, >>> >>> I know it is a simple question. But for me, at current, I fail to

Re: [R] Generate random Bernoulli draws

2018-07-06 Thread Duncan Murdoch
On 06/07/2018 1:18 PM, Berry, Charles wrote: A liitle math goes along way. See below. On Jul 5, 2018, at 10:35 PM, Marino David wrote: Dear Bert, I know it is a simple question. But for me, at current, I fail to implement it. So, I ask for help here. It is not homework. Best, David 2018-

Re: [R] Generate random Bernoulli draws

2018-07-06 Thread Göran Broström
On 2018-07-06 19:18, Berry, Charles wrote: A liitle math goes along way. See below. On Jul 5, 2018, at 10:35 PM, Marino David wrote: Dear Bert, I know it is a simple question. But for me, at current, I fail to implement it. So, I ask for help here. It is not homework. Best, David 2018

Re: [R] Generate random Bernoulli draws

2018-07-06 Thread Berry, Charles
A liitle math goes along way. See below. > On Jul 5, 2018, at 10:35 PM, Marino David wrote: > > Dear Bert, > > I know it is a simple question. But for me, at current, I fail to implement > it. So, I ask for help here. > > It is not homework. > > Best, > > David > > 2018-07-06 13:32 GMT+08:0

Re: [R] Generate random Bernoulli draws

2018-07-06 Thread Marino David
Dear Ben, Thanks a lot for your reply. Best, David 2018-07-06 19:33 GMT+08:00 Ben Tupper : > Hi, > > I haven't any idea about what you ask, but I do know that Rseek.org is a > gold mine! Check out... > > https://rseek.org/?q=Bernoulli+random+variable > > Cheers, > Ben > > On Jul 6, 2018, at 1

Re: [R] Generate random Bernoulli draws

2018-07-06 Thread Ben Tupper
Hi, I haven't any idea about what you ask, but I do know that Rseek.org is a gold mine! Check out... https://rseek.org/?q=Bernoulli+random+variable Cheers, Ben > On Jul 6, 2018, at 1:35 AM, Marino David wrote: > > Dear Be

Re: [R] Generate random Bernoulli draws

2018-07-05 Thread Marino David
Dear Bert, I know it is a simple question. But for me, at current, I fail to implement it. So, I ask for help here. It is not homework. Best, David 2018-07-06 13:32 GMT+08:00 Bert Gunter : > Is this homework? > > (There is an informal no-homework policy on this list). > > Cheers, > Bert > > >

Re: [R] Generate random Bernoulli draws

2018-07-05 Thread Bert Gunter
Is this homework? (There is an informal no-homework policy on this list). Cheers, Bert 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 Thu, Jul 5, 2018 at 10

[R] Generate random Bernoulli draws

2018-07-05 Thread Marino David
Dear All, I would like to generate N random Bernoulli draws given a probability function F(x)=1-exp(-2.5*x) in which x follows uniform distribution, say x~U(0,2). Can some one leave me some code lines for implementing this? Thanks in advance. David [[alternative HTML version deleted]]

Re: [R] Generate N random numbers with a given probability and condition

2018-07-04 Thread Rolf Turner
On 05/07/18 10:21, Nelly Reduan wrote: Dear all, I would like to generate N random numbers with a given probability and condition but I'm not sure how to do this. For example, I have N = 20 and the vector from which to choose is seq(0, 10, 1). I have tested: x <- sample(seq(0, 10, 1), 20,

Re: [R] Generate N random numbers with a given probability and condition

2018-07-04 Thread Jeff Newmiller
This looks like homework (which is off topic here per the Posting Guide). Also, please send your emails in plain text format to avoid us seeing your message differently than you do. On July 4, 2018 3:21:34 PM PDT, Nelly Reduan wrote: >Dear all, > >I would like to generate N random numbers with

[R] Generate N random numbers with a given probability and condition

2018-07-04 Thread Nelly Reduan
Dear all, I would like to generate N random numbers with a given probability and condition but I'm not sure how to do this. For example, I have N = 20 and the vector from which to choose is seq(0, 10, 1). I have tested: x <- sample(seq(0, 10, 1), 20, replace=TRUE, prob=rep(0.28, times=length(se

Re: [R] Generate simulated data respecting some conditions

2017-07-06 Thread Jeff Newmiller
Yes, definitely. However, this is so close to being legal R code that I feel you have not made any effort to translate it yourself, and this is the "R-help" mailing list, not the "R-do-my-work-for-me" mailing list. Is this homework? Have you read the "Introduction to R" document that is supplie

[R] Generate simulated data respecting some conditions

2017-07-06 Thread Marine Regis
Hello, Is it possible to generate simulated data that look like the attached figure? The curve in the figure can be obtained from this equation respecting some conditions: if(Temperature > T_min & Temperature < T_max){ a*( Temperature -T_min)*( Temperature -T_max) } else 0 T_min ~ Unif

[R] Generate correlated expontial distribution -- lamda please guide

2017-06-15 Thread Sunny Singha
Hi, I need to generate correlated (positive as well as negative) bivariate exponential distribution with rate of 1/5 or any rate I need some guidance here. Please help. Regards, Sunny __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] generate a vector of random numbers within confines of certain parameters

2016-08-02 Thread Bert Gunter
All floating point operations are done to machine precision -- roughly 16 digits. See ?.Machine . You can choose to round, truncate, or display to anything less than that that you care to. See also the digits parameter of ?options The rest of your post is ambiguous to me. But note that (all?/most

Re: [R] generate a vector of random numbers within confines of certain parameters

2016-08-02 Thread Jeff Newmiller
x <- rnorm( 2, 5, 2.5 ) The requirement for "random" is ill-specified because it omits mention of which random distribution you want (I assumed normal distribution above). The requirement for "decimal places" is ill-defined because floating point numbers are internally represented with mant

Re: [R] generate a vector of random numbers within confines of certain parameters

2016-08-02 Thread David L Carlson
-Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David L Carlson Sent: Tuesday, August 2, 2016 2:40 PM To: Adrian Johnson; r-help Subject: Re: [R] generate a vector of random numbers within confines of certain parameters Try > set.seed(42) > x1 <- ro

Re: [R] generate a vector of random numbers within confines of certain parameters

2016-08-02 Thread David L Carlson
ian Johnson Sent: Tuesday, August 2, 2016 1:57 PM To: r-help Subject: [R] generate a vector of random numbers within confines of certain parameters Dear group, I am trying to generate a vector of random numbers for 20K observation. however, I want to generate numbers (with 6 decimal places) within th

[R] generate a vector of random numbers within confines of certain parameters

2016-08-02 Thread Adrian Johnson
Dear group, I am trying to generate a vector of random numbers for 20K observation. however, I want to generate numbers (with 6 decimal places) within the range of Std. Dev : 2-3 mean : 4-6 Is there a method to generate numbers with 6 decimal places under these parameters thank you. Adrian __

Re: [R] Generate list if sequence form two vector element

2016-06-23 Thread PIKAL Petr
; Cc: R-help Mailing List > Subject: Re: [R] Generate list if sequence form two vector element > > Hi Tanvir, > Not at all elegant, but: > > make.seq<-function(x) return(seq(x[1],x[2])) > apply(matrix(c(a,b),ncol=2),1,make.seq) > > Jim > > > On Wed, Jun 22, 2016 a

Re: [R] Generate list if sequence form two vector element

2016-06-22 Thread Jim Lemon
Hi Tanvir, Not at all elegant, but: make.seq<-function(x) return(seq(x[1],x[2])) apply(matrix(c(a,b),ncol=2),1,make.seq) Jim On Wed, Jun 22, 2016 at 5:32 PM, Mohammad Tanvir Ahamed via R-help wrote: > Hi, > I want to do the follow thing > > Input : > a <- c(1,3,6,9) > > > b<-c(10,7,20,2) > > >

[R] Generate list if sequence form two vector element

2016-06-22 Thread Mohammad Tanvir Ahamed via R-help
Hi, I want to do the follow thing Input : a <- c(1,3,6,9) b<-c(10,7,20,2) Expected outcome : d<-list(1:10,3:7,6:20,2:9) Thanks !! Tanvir Ahamed Göteborg, Sweden | mashra...@yahoo.com __ R-help@r-project.org mailing list -- To UNSUBS

Re: [R] generate levels with different number of replications with gl() function

2016-02-10 Thread David Barron
Why not use rep instead of gl: levels <- c('BR', 'CNS', 'CO', 'LE', 'ME', 'LC', 'OV', 'PR', 'RE') reps <- c(4, 6, 7, 6, 10, 9, 7, 2, 8) rep(levels, reps) David On 10 February 2016 at 05:02, hehsham alpukhity via R-help < r-help@r-project.org> wrote: > I am trying to use the function gl (generat

[R] generate levels with different number of replications with gl() function

2016-02-09 Thread hehsham alpukhity via R-help
I am trying to use the function gl (generate levels with different number of replications), generate different number of replications in each level.examplei have factor with this levels (BR,CNS ,CO,LE,ME,LC,OV,PR,RE),  and the replications is not the same , i want (4 replication for BR),( 6 repl

[R] Generate arrival of time based on uniform random number

2016-02-03 Thread smart hendsome via R-help
Hi everyone, I have problem regarding to generate arrival of time based on uniform random number. Let day0 = 0.383, lambda = 0.2612 1) Generate uniform random number (already settled) using the code below: set.seed(1234) rand.no <- function(n,itr){   matrix(runif(n*itr, 0, 1), nrow=n, ncol=itr) }

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Marc Schwartz
> On Sep 16, 2015, at 3:40 PM, Bert Gunter wrote: > > Nope. Take it back. I stand uncorrected. > >> system.time(z <-sample(1:10,1e6, rep=TRUE)) > user system elapsed > 0.045 0.001 0.047 > >> system.time(z <-sample.int(10,1e6,rep=TRUE)) > user system elapsed > 0.012 0.000 0.013

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Bert Gunter
Nope. Take it back. I stand uncorrected. > system.time(z <-sample(1:10,1e6, rep=TRUE)) user system elapsed 0.045 0.001 0.047 > system.time(z <-sample.int(10,1e6,rep=TRUE)) user system elapsed 0.012 0.000 0.013 sample() has to do subscripting in the general case; sample.int d

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Bert Gunter
Yes. Thanks Marc. I stand corrected. -- Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Wed, Sep 16, 2015 at 1:28 PM, Marc Schwartz wrote: > >> On Sep 16, 2015, at 1:06 PM, Bert Gunter wrote: >> >> Yikes!

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Marc Schwartz
> On Sep 16, 2015, at 1:06 PM, Bert Gunter wrote: > > Yikes! The uniform distribution is a **continuous** distribution over > an interval. You seem to want to sample over a discrete distribution. > See ?sample for that, as in: > > sample(1:4,100,rep=TRUE) > > ## or for this special case and fa

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Bert Gunter
Yikes! The uniform distribution is a **continuous** distribution over an interval. You seem to want to sample over a discrete distribution. See ?sample for that, as in: sample(1:4,100,rep=TRUE) ## or for this special case and faster sample.int(4,size=100,rep=TRUE) Cheers, Bert Bert Gunter "Da

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Marc Schwartz
> On Sep 16, 2015, at 12:11 PM, thanoon younis > wrote: > > Dear R- users > > I want to generate ordered categorical variable vector with 200x1 dimension > and from 1 to 4 categories and i tried with this code > > Q1=runif(200,1,4) the results are not just 1 ,2 3,4, but the results with > dec

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread David L Carlson
TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of thanoon younis Sent: Wednesday, September 16, 2015 12:11 PM To: r-help@r-project.org Subject: [R] generate ordered categorical variable in R Dear R- users I want to generate ordered categorical va

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Rui Barradas
Hello, Try ?sample. Hope this helps, Rui Barradas Em 16-09-2015 18:11, thanoon younis escreveu: Dear R- users I want to generate ordered categorical variable vector with 200x1 dimension and from 1 to 4 categories and i tried with this code Q1=runif(200,1,4) the results are not just 1 ,2 3,4

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Michael Dewey
If I understand correctly ?sample On 16/09/2015 18:11, thanoon younis wrote: Dear R- users I want to generate ordered categorical variable vector with 200x1 dimension and from 1 to 4 categories and i tried with this code Q1=runif(200,1,4) the results are not just 1 ,2 3,4, but the results wi

[R] generate ordered categorical variable in R

2015-09-16 Thread thanoon younis
Dear R- users I want to generate ordered categorical variable vector with 200x1 dimension and from 1 to 4 categories and i tried with this code Q1=runif(200,1,4) the results are not just 1 ,2 3,4, but the results with decimals like 1.244, 2.342,4,321 and so on ... My question how can i generate a

Re: [R] Generate a vector of values, given a vector of keys and a table?

2015-09-11 Thread David Wolfskill
On Fri, Sep 11, 2015 at 04:42:07PM +0200, peter dalgaard wrote: > Or change the data format slightly and use indexing: > > > l > keyval > [1,] "1.1" "1" > [2,] "1.9" "1" > [3,] "1.4" "15000" > [4,] "1.5" "2" > [5,] "1.15" "25000" > > v <- l[,2] > > names(v) <- l[,1] >

Re: [R] Generate a vector of values, given a vector of keys and a table?

2015-09-11 Thread peter dalgaard
Or change the data format slightly and use indexing: > l keyval [1,] "1.1" "1" [2,] "1.9" "1" [3,] "1.4" "15000" [4,] "1.5" "2" [5,] "1.15" "25000" > v <- l[,2] > names(v) <- l[,1] > x <- c("1.9", "1.9", "1.1", "1.1", "1.4", "1.4", "1.5", "1.5", "1.5", + "1.5") > v[x]

Re: [R] Generate a vector of values, given a vector of keys and a table?

2015-09-11 Thread David Wolfskill
On Thu, Sep 10, 2015 at 10:30:50PM -0700, Bert Gunter wrote: > ?match > > as in: > > > y <- lk_up[match(x,lk_up[,"key"]),"val"] > > y > [1] "1" "1" "1" "1" "15000" "15000" "2" > [8] "2" "2" "2" > ... Aye -- thank you very much! Peace, david -- David H. Wolfski

Re: [R] Generate a vector of values, given a vector of keys and a table?

2015-09-10 Thread Bert Gunter
?match as in: > y <- lk_up[match(x,lk_up[,"key"]),"val"] > y [1] "1" "1" "1" "1" "15000" "15000" "2" [8] "2" "2" "2" Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On

[R] Generate a vector of values, given a vector of keys and a table?

2015-09-10 Thread David Wolfskill
I apologize in advance: I must be overlooking something quite simple, but I'm failing to make progress. Suppose I have a "lookup table": Browse[2]> dput(lk_up) structure(c("1.1", "1.9", "1.4", "1.5", "1.15", "1", "1", "15000", "2", "25000"), .Dim = c(5L, 2L), .Dimnames = list( NU

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread William Dunlap
Look more at help(rep) and help(seq): > n <- 7 > rep(seq_len(n), each=4) [1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 Bill Dunlap TIBCO Software wdunlap tibco.com On Sun, Apr 19, 2015 at 6:44 AM, John Sorkin wrote: > Windows 7 64-bit > R 3.1.3 > RStudio 0.98.1103 > > >

[R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread John Sorkin
Windows 7 64-bit R 3.1.3 RStudio 0.98.1103 I am trying to generate a list of length 4n which consists of the integers 1 to n repeated in groups of four, i.e. 1,1,1,1, 2,2,2,2, 3,3,3,3, . . . . , n,n,n,n (The spaces in the list are added only for clarity.) I can generate the list as follow

[R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread John Sorkin
Windows 7 64-bit R 3.1.3 RStudio 0.98.1103 I am trying to generate a list of length 4n which consists of the integers 1 to n repeated in groups of four, i.e. 1,1,1,1, 2,2,2,2, 3,3,3,3, . . . . , n,n,n,n (The spaces in the list are added only for clarity.) I can generate the list as follow

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread SOUVIK BANDYOPADHYAY
Hi, You can use the apply group of functions n<-5 k<-4 unlist(lapply(1:n,rep, each=k)) # For vector output: sapply(1:n,rep, each=k) # For a matrix output Hope this helps Souvik On Sun, Apr 19, 2015 at 7:14 PM, John Sorkin wrote: > Windows 7 64-bit > R 3.1.3 > RStudio 0.98.1103 > > > I am tryi

[R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread John Sorkin
Windows 7 64-bit R 3.1.3 RStudio 0.98.1103 I am trying to generate a list of length 4n which consists of the integers 1 to n repeated in groups of four, i.e. 1,1,1,1, 2,2,2,2, 3,3,3,3, . . . . , n,n,n,n (The spaces in the list are added only for clarity.) I can generate the list as fo

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Boris Steipe
That would be the "each" argument to rep()... n <- 5 rep(1:n, each=4) [1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 Cheers, B. On Apr 19, 2015, at 9:44 AM, John Sorkin wrote: > Windows 7 64-bit > R 3.1.3 > RStudio 0.98.1103 > > > I am trying to generate a list of length 4n which consists of

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Gerrit Eichner
Hi, John, doesn't n <- lapply( 1:n, rep, each = 4) do what you need? Hth -- Gerrit On Sat, 18 Apr 2015, John Sorkin wrote: Windows 7 64-bit R 3.1.3 RStudio 0.98.1103 I am trying to generate a list of length 4n which consists of the integers 1 to n repeated in groups of four, i.e.

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Sven E. Templer
In '?rep' find out about the 'each' argument. Also there is the function 'gl' which creates a factor and offers a shorter syntax for your problem. If n equals 5 use one of: rep(seq(5), each = 4) gl(5,4) On 19 April 2015 at 15:44, John Sorkin wrote: > Windows 7 64-bit > R 3.1.3 > RStudio 0.98.1

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Michael Dewey
On 19/04/2015 15:34, John Sorkin wrote: Windows 7 64-bit R 3.1.3 RStudio 0.98.1103 I am trying to generate a list of length 4n which consists of the integers 1 to n repeated in groups of four, i.e. 1,1,1,1, 2,2,2,2, 3,3,3,3, . . . . , n,n,n,n (The spaces in the list are added only for c

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Ben Tupper
On Apr 19, 2015, at 9:44 AM, John Sorkin wrote: > Windows 7 64-bit > R 3.1.3 > RStudio 0.98.1103 > > > I am trying to generate a list of length 4n which consists of the integers 1 > to n repeated in groups of four, i.e. > > 1,1,1,1, 2,2,2,2, 3,3,3,3, . . . . , n,n,n,n > Hi, Like this?

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Rmh
rep(1:n, each=4) Sent from my iPhone > On Apr 19, 2015, at 09:44, John Sorkin wrote: > > Windows 7 64-bit > R 3.1.3 > RStudio 0.98.1103 > > > I am trying to generate a list of length 4n which consists of the integers 1 > to n repeated in groups of four, i.e. > > 1,1,1,1, 2,2,2,2, 3,3,3,3

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Jeff Newmiller
You are not generating lists, you are generating vectors. Try rep( seq.int( n ), each= 4 ) --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go...

[R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread John Sorkin
Windows 7 64-bit R 3.1.3 RStudio 0.98.1103 I am trying to generate a list of length 4n which consists of the integers 1 to n repeated in groups of four, i.e. 1,1,1,1, 2,2,2,2, 3,3,3,3, . . . . , n,n,n,n (The spaces in the list are added only for clarity.) I can generate the list as follow

[R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-19 Thread John Sorkin
Windows 7 64-bit R 3.1.3 RStudio 0.98.1103 I am trying to generate a list of length 4n which consists of the integers 1 to n repeated in groups of four, i.e. 1,1,1,1, 2,2,2,2, 3,3,3,3, . . . . , n,n,n,n (The spaces in the list are added only for clarity.) I can generate the list as follow

  1   2   3   4   >