[R-sig-eco] subsetting in R

Peter Solymos solymos at ualberta.ca
Wed Sep 19 00:00:04 CEST 2012


Kristen,

Try something like this:

i <- sample(1:nrow(DataSet.Sub2), 85, replace=FALSE)
DataSet.Sub2.66<- DataSet.Sub2[i,]
DataSet.Sub2.33<- DataSet.Sub2[-i,]

Peter

--
Péter Sólymos, Dept Biol Sci, Univ Alberta, T6G 2E9, Canada AB
solymos at ualberta.ca, Ph 780.492.8534, http://psolymos.github.com
Alberta Biodiversity Monitoring Institute, http://www.abmi.ca
Boreal Avian Modelling Project, http://www.borealbirds.ca


On Tue, Sep 18, 2012 at 3:56 PM, Kristen Gorman <kgorman at sfu.ca> wrote:
> Dear all,
> I have a dataset where I would like to take 2/3 of the data to build a model and test it on the remaining 1/3 of the dataset. In order to generate the 2/3 dataset I have the following code:
>
> # 85 is .66 of 129 in order to generate random number for 2/3 dataset.
> DataSet.Sub2.66<- DataSet.Sub2[sample(1:nrow(DataSet.Sub2), 85, replace=FALSE),]
>
> Now, I would like to generate a separate dataset from the remaining 1/3 dataset not selected for the 2/3 dataset. Any ideas on how best to do this?
>
>
> Thanks for any input,
>
> Kristen
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



More information about the R-sig-ecology mailing list