Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
u can just remove the lines with X1 = 0 since you don't want to use them. > > tab.sub <- tab[tab$X1>0, ] > > Then the following gives you a sample: > > tab.sub[cumsum(sample(tab.sub$X2))<=500, ] > > Note, that your "solution" of times 6, 7, and 8 will never

Re: [R] Conditional Random selection

2015-11-21 Thread ruipbarradas
t() to send data to the list as it is more compact: >> >> dput(tab) >> >> structure(list(time = 1:8, X1 = c(0L, 5L, 1L, 0L, 2L, 3L, 1L, >> 4L), X2 = c(251L, 230L, 300L, 25L, 10L, 101L, 300L, 185L)), .Names = >> c("time", >> "X1", "X2

Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
th X1 = 0 since you don't want to use them. > > tab.sub <- tab[tab$X1>0, ] > > Then the following gives you a sample: > > tab.sub[cumsum(sample(tab.sub$X2))<=500, ] > > Note, that your "solution" of times 6, 7, and 8 will never appear because > th

Re: [R] Conditional Random selection

2015-11-21 Thread ruipbarradas
ut(tab) >>>>> >>>>> structure(list(time = 1:8, X1 = c(0L, 5L, 1L, 0L, 2L, 3L, 1L, >>>>> 4L), X2 = c(251L, 230L, 300L, 25L, 10L, 101L, 300L, 185L)), >>>>> .Names = c("time", >>>>> "X1", "X2"),

Re: [R] Conditional Random selection

2015-11-21 Thread Bert Gunter
gt;>>> c("time", >>>>> "X1", "X2"), class = "data.frame", row.names = c(NA, -8L)) >>>>> >>>>> You can just remove the lines with X1 = 0 since you don't want to use >>>>> them. >>>

Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
0 since you don't want to use them. >>>> >>>>> tab.sub <- tab[tab$X1>0, ] >>>> >>>> Then the following gives you a sample: >>>> >>>>> tab.sub[cumsum(sample(tab.sub$X2))<=500, ] >>>> >>&g

Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
ab$X1>0, ] >>> >>> Then the following gives you a sample: >>> >>>> tab.sub[cumsum(sample(tab.sub$X2))<=500, ] >>> >>> Note, that your "solution" of times 6, 7, and 8 will never appear because >>> the sum of the values i

Re: [R] Conditional Random selection

2015-11-21 Thread Bert Gunter
and 8 will never appear because >> the sum of the values is 586. >> >> >> David L. Carlson >> Department of Anthropology >> Texas A&M University >> >> -Original Message- >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf O

Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
t; of times 6, 7, and 8 will never appear because the > sum of the values is 586. > > > David L. Carlson > Department of Anthropology > Texas A&M University > > -Original Message----- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ashta > Sent: Satur

Re: [R] Conditional Random selection

2015-11-21 Thread David L Carlson
ll never appear because the sum of the values is 586. David L. Carlson Department of Anthropology Texas A&M University -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ashta Sent: Saturday, November 21, 2015 11:53 AM To: R help Subject: [R] Conditional

[R] Conditional Random selection

2015-11-21 Thread Ashta
Hi all, I have a data set that contains samples collected over time. In each time period the total number of samples are given (X2) The goal is to select 500 random samples.The selection should be based on time (select time periods until I reach 500 samples). Also the time period should