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 wrote:
> All,
>
> I have data that looks like below. For each id there may be more than one
> value per day. I want
On Thu, Jul 2, 2009 at 8:15 AM, James Martin 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 for it randomly ch
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 val
On Wed, Jul 1, 2009 at 2:10 PM, Sunil
Suchindran 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 observation from each
#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,
df$
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 her
6 matches
Mail list logo