Skip to content
Back to formatted view

Raw Message

Message-ID: <9F4ADCFE-3AED-4595-BFBA-BC28553F89BB@xs4all.nl>
Date: 2012-09-13T08:58:15Z
From: Berend Hasselman
Subject: random sampling inside a dataset
In-Reply-To: <CAPxEaETGkvMqNN8N-6iqjwqmwbiZqcYzs4M54-bP1E=Kh6QUmA@mail.gmail.com>

On 13-09-2012, at 10:42, Gian Maria Niccol? Benucci wrote:

> Hi all,
> 
> I am wondering if do exist a function in R that allow me to sample or
> choose randomly the rows (i.e., samples) inside a given matrix.

Use sample.
Like this for example

A <- matrix(runif(8*4), nrow=8)
A

select.row <- sample(1:nrow(A), size= nrow(A)/3, replace=FALSE)
select.row
A[select.row,]

Berend