Hi:

One way to permute your sample 1000 times is to use the r*ply() function
from the plyr package. Let s denote your original vector, randomly generated
as follows:

s <- rbinom(800, 0.6)               # simulates your Yes/No vector
library(plyr)
u <- raply(1000, sample(s))    # generates a 1000 x 800 matrix

As Steve mentioned, you can also use replicate():

v <- replicate(1000, sample(r))     # generates an 800 x 1000 matrix

# With mydata as your original data frame, the 1000 reshuffles can be
attached with
df <- data.frame(mydata, t(u))                  # or  df <-
data.frame(mydata, v)
names(df)[3:1002] <- paste('S', 1:1000, sep = '')
write.csv(df, file = 'myExcelFile.csv', quote = FALSE, row.names = FALSE)

Substitute your input vector for s in the raply() call. [Note that
replicate() is about 10 times faster than raply() for this example.]
The result should be an 800 x 1002 (two original variables + 1000
reshuffles) data frame. Writing to a csv file is a convenient intermediary
between R and Excel, but there are several ways to write data from R to
Excel. See
http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows

HTH,
Dennis

On Mon, Oct 18, 2010 at 4:37 AM, Peter Francis <peterfrancis@me.com> wrote:

> Dear List,
>
> I have a table i have read into R:
>
> Name    Yes/No
>
> John    0
> Frank   1
> Ann             0
> James   1
> Alex    1
>
> etc  - 800 different times.
>
> What i want to do is shuffle yes/no and randomly re-assign them to the
> name.
>
> I have used sample() and permute(), however there is no way to do this 1000
> times. Furthermore, i want to copy the data into a excel spreadsheet in the
> same order as the data was input so i can build up a distribution of the
> statistic for each name. When i use shuffle the date gets returned like this
> -
>
> [1] 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1
>  [34] 0 1 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0
>  [67] 0 0 0 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1
>  [100] 1 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0
>  [133] 0 0 0 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0
>  [166] 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 0 1
>  [199] 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1
>  [232] 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1
>  [265] 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1
>  [298] 0 1 1 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0
>  [331] 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1
>
> etc
>
> Rather than like this
>
> John    0
> Frank   1
> Ann             0
> James   1
> Alex    1
>
> Can anyone suggest a script that would achieve this?
>
> Thanks
>
> Peter
>
> ______________________________________________
> 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]]

