Emma,

If you haven't spent much time on the r-help forums, please do read the
posting guide.

You need to provide reproducible examples for us to help you.

We don't know anything about your data...

what is event.details, (if you can't provide the data often ?str will do)

since I don't know what event.details is, I can't figure out waht the line:


obs = (1:133429)[event.details[,2] == i]

is supposed to do.

But if I had to guess... ?sample says it expects the first argument as a
vector.  I assume obs is not a vector but a larger structure?

Feel free to post more info about your data (see ?str and ?dput) or if you
can generate made up data that replicates your problem that works too.


Justin


On Wed, Dec 7, 2011 at 9:16 AM, bevare <emma.raven@jbaconsulting.co.uk>wrote:

> Hi,
>
> Can anyone help sort out the problem with the following script - I am a R
> newbie and I am self taught.
>
> obs.all = c()
> for(i in 1:386){
>  if (n.sim[i]>0){
>    obs = (1:133429)[event.details[,2] == i]
>    obs.all = c(obs.all, sample(obs[obs < n.sim[i]], size = n.sim[i],
> replace=T))
>    }
>
> Basically, in the sample bit, I only want to get obs.all if the value of
> obs
> is less than the value of n.sim[i]. I get the error message
>
> Error in sample(obs[obs < n.sim[i]], size = n.sim[i], replace = T) :
>  invalid first argument
>
> length(n.sim)  is 386
>
> Thanks in advance for your suggestions
>
> Emma
>
>
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/using-sample-tp4169747p4169747.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

