nBuyMat <- data.frame(matrix(rnorm(28), 7, 4))
nBuyMat
nBuy <- nrow(nBuyMat)
sample(1:nBuy, nBuy, replace=FALSE)
sample(1:nBuy)
sample(nBuy)
?sample
apply(nBuyMat[sample(1:nBuy,nBuy, replace=FALSE),], 1, function(x) sum(x))

apply(nBuyMat[sample(nBuy),], 1, function(x) sum(x))


The defaults for sample do what you have requested.

If the original row identification matters, then be sure the to use
either a matrix with rownames or a data.frame.

Rich


Sent from my iPhone

> On Nov 10, 2016, at 08:06, Thomas Chesney <thomas.ches...@nottingham.ac.uk> 
> wrote:
>
> for (b in sample(1:nBuy,nBuy, replace=FALSE)){
>
> }
>
> but
>
> apply(nBuyMat, 1, function(x))

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to