[R] Sampling problem

Michael Bedward michael.bedward at gmail.com
Tue Nov 16 09:27:28 CET 2010


On 16 November 2010 16:10, wangwallace <talenttree at gmail.com> wrote:
>
> Michael, I really appreciate your help.
>
> but I got the following error message when I wan trying to run the function
> written by you:
>
> Error in out[i, ] <- apply(help[, c(grp1 + 1, grp2 + 5)], 2, sample, 1) :
>  number of items to replace is not a multiple of replacement length

Did the data.frame or matrix you were sampling have the same general
form as the example you posted previously ?  Can you give me a small
example that causes the error ?

> I am not quite sure why would this happen.
>
> As a novice of R, these functions are kinda complex for me. I am wondering
> if it is doable without using loops like that.

I wasn't sure exactly what you wanted so the function was meant to be
general and easy to modify. It is often possible to use constructs
other than loops in R, though that doesn't mean the code will always
be either faster or clearer. But you'll need to describe your
requirements in more precise terms (short, clear examples are good)
for folks here to suggest methods.

>
> Again, thank you so much!!!

No worries. If you can provide an example that generates the error we
should be able to get further.

Michael



More information about the R-help mailing list