Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
Thank you ! I was also able to do it this way, too! hc <- ddply(tab1, .(time), summarize, S1 = length(unique(S1))) On Sat, Nov 21, 2015 at 3:40 PM, wrote: > Hello, > > Is that a real doubt? Like Bert said, you should spend some time with an R > tutorial. All you need is to know how to form a

Re: [R] Conditional Random selection

2015-11-21 Thread ruipbarradas
Hello, Is that a real doubt? Like Bert said, you should spend some time with an R tutorial. All you need is to know how to form a data.frame. tmp <- tapply(tab1$S1, tab1$time, function(x) length(unique(x))) data.frame(time = names(tmp), S1 = tmp) Rui Barradas   Citando Ashta : > Hi  Rui , >

Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
Hi Rui , I tried that one before I send out my original message. it gave me only this, tapply(tab$S1, tab$time, function(x) length(unique(x))) 1 2 3 2 1 3 I am expecting an output of like this time S1 12 21 33 On Sat, Nov 21, 2015 at 2:38 PM, wrote: > Hello,

Re: [R] Conditional Random selection

2015-11-21 Thread ruipbarradas
Hello, Try tapply(tab$S1, tab$time, function(x) length(unique(x))) Hope this helps, Rui Barradas   Citando Ashta : > Hi  Bert  and all, > I have related question.  In each  time period there were different > locations where the samples were collected (S1).   I  want count  the > number of uni

Re: [R] Conditional Random selection

2015-11-21 Thread Bert Gunter
Time to do your own homework by working through an R tutorial or two. There are many on the web -- or see the Intro to R tutorial that ships with R. ?tapply ?unique is one of many answers to your query. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowled

Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
Hi Bert and all, I have related question. In each time period there were different locations where the samples were collected (S1). I want count the number of unique locations (S1) for each unique time period . So in time 1 the samples were collected from two locations and time 2 only from

Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
Thank you Bert! What I want is at least 500 samples based on random sampling of time period. This allows samples collected at the same time period are included together. Your script is doing what I wanted to do!! Many thanks On Sat, Nov 21, 2015 at 1:15 PM, Bert Gunter wrote: > David's "

Re: [R] Conditional Random selection

2015-11-21 Thread Bert Gunter
David's "solution" is incorrect. It can also fail to give you times with a total of 500 items to sample from in the time periods. It is not entirely clear what you want. The solution below gives you a random sample of time periods in which X1>0 and the total number of samples among them is >= 500.

Re: [R] Conditional Random selection

2015-11-21 Thread Ashta
Thank you David! I rerun the your script and it is giving me the first three time periods is it doing random sampling? tab.fan time X1 X2 22 5 230 33 1 300 55 2 10 On Sat, Nov 21, 2015 at 12:20 PM, David L Carlson wrote: > Use dput() to send data to the list as it is

Re: [R] Conditional Random selection

2015-11-21 Thread David L Carlson
Use dput() 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"), class = "data.frame", row.names = c(NA, -8L)) You can just remove the