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
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
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
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"),
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.
>>>
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
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
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
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
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
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
11 matches
Mail list logo