[R] random sample from a file
Petr Pikal
petr.pikal at precheza.cz
Mon Jun 5 13:29:30 CEST 2006
Hi
sample a vector from 1 to the number of rows in of your file and
subset a file with sampled values
> iris[sample(1:nrow(iris), 20),]
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
99 5.1 2.5 3.0 1.1 versicolor
53 6.9 3.1 4.9 1.5 versicolor
40 5.1 3.4 1.5 0.2 setosa
146 6.7 3.0 5.2 2.3 virginica
93 5.8 2.6 4.0 1.2 versicolor
....
HTH
Petr
On 5 Jun 2006 at 11:09, Tibi Codilean wrote:
Date sent: Mon, 5 Jun 2006 11:09:50 +0100
From: "Tibi Codilean" <Tibi.Codilean at ges.gla.ac.uk>
To: r-help at stat.math.ethz.ch
Subject: [R] random sample from a file
> Dear All,
>
>
> Thanks to all that responded to my earlier query.
>
>
> I have a file with two columns: an ID field and a Data field. I wish
> to extract multiple random samples of 20 numbers from this file in
> such a way that the ID field is extracted with the data as well. At
> the moment I am using the 'sample' function but this only extracts the
> data without the IDs. The file is a comma separated text file and I
> read it in using read.csv
>
>
> Could you please tell me if there is a way of doing this such that
> every random sample contains both the ID and the data.
>
>
> Thanks
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list