Re: [R] Select values at random by id value

2009-07-02 Thread James Martin
Hadley, Sunil, and list, This is not quite doing what I wanted it to do (as far as I can tell). I perhaps did not explain it thoroughly. It seems to be sampling one value for each day leaving ~200 observations. I need for it randomly chose one hab value for each bird if there is more than one

Re: [R] Select values at random by id value

2009-07-02 Thread hadley wickham
On Thu, Jul 2, 2009 at 8:15 AM, James Martinjust.strut...@gmail.com wrote: Hadley, Sunil, and list, This is not quite doing what I wanted it to do (as far as I can tell). I perhaps did not explain it thoroughly.  It seems to be sampling one value for each day leaving ~200 observations. I need

Re: [R] Select values at random by id value

2009-07-02 Thread James Martin
ddply(df, c(date, id), function(df) df[sample(nrow(df), 1), ]) Thanks to Hadley and Sunil. The above code solves my problem. jm On Mon, Jun 29, 2009 at 9:11 AM, James Martin just.strut...@gmail.comwrote: All, I have data that looks like below. For each id there may be more than one value

Re: [R] Select values at random by id value

2009-07-01 Thread Sunil Suchindran
#Highlight the text below (without the header) # read the data in from clipboard df - do.call(data.frame, scan(clipboard, what=list(id=0, date=,loctype=0 ,haptype=0))) # split the data by date, sample 1 observation from each split, and rbind sampled_df - do.call(rbind, lapply(split(df,

Re: [R] Select values at random by id value

2009-07-01 Thread hadley wickham
On Wed, Jul 1, 2009 at 2:10 PM, Sunil Suchindransunilsuchind...@gmail.com wrote: #Highlight the text below (without the header) # read the data in from clipboard df - do.call(data.frame, scan(clipboard, what=list(id=0, date=,loctype=0 ,haptype=0))) # split the data by date, sample 1

[R] Select values at random by id value

2009-06-29 Thread James Martin
All, I have data that looks like below. For each id there may be more than one value per day. I want to select a random value for that day for that id. The end result would hopefully be a matrix with the id as rows, date as columns and populated by the random hab value. Thanks to someone on