[R] Questions about generating samples in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Nov 27 09:41:40 CET 2006


Christian Schulz <ozric at web.de> writes:

> split <- sample(2,nrow(dataframe),replace=T,prob=c(0.04,0.96))
> 
> dataframe[split==1,]  # 200
> dataframe[split==2,] # 4800
> 
> regards, christian
> 
> > ?sample should tell you what you need to know.

It does, but the above is not how. To get exactly 200 samples, use

sel <- sample(200, nrow(dataframe))
dataframe[sel,]

> > On 26/11/06, Alexander Geisler <alexander.geisler at gmail.com> wrote:
> >   
> >> Hello!
> >>
> >> I have a data set with 8 columns and in about 5000 rows. What I want to
> >> do is to generate samples of this data set.
> >>
> >> Samples of a special size, as example 200.
> >>
> >> What is the easiest way to do this? No special things are needed, only
> >> the random selection of 200 rows of the data set.
> >>
> >> Thanks
> >> Alex
> >>
> >> --
> >> Alexander Geisler * Kaltenbach 151 * A-6272 Kaltenbach
> >> email: alexander.geisler at gmx.at | alexander.geisler at gmail.com
> >> phone: +43 650 / 811 61 90 | skpye: al1405ex
> >>
> >> ______________________________________________
> >> 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
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>     
> >
> >
> >
> 
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list