Or something like that: s <- sample(121, 80) df1 <- df[s,] df2 <- df[-s,]
which is pretty similar Wilfried Robert J. Hijmans a écrit : > Gianni, > > I think the problem is that you call sample twice. Do something like: > > df <- data.frame(matrix(1:240,nrow=120)) > s <- sample(120) > df1 <- df[s[1:80],] > df2 <- df[s[81:120],] > > Robert > > On Thu, Oct 8, 2009 at 9:45 PM, gianni lavaredo > <[email protected]>wrote: > > >> thanks for help >> >> I have a data.frame with 121 rows. I wish to split random in two >> data.frames >> (first = 80 rows and second = 41 rows). I try this code >> >> dat1 <- AnalysisDF_clean[sample(1:nrow(AnalysisDF_clean), >> 80,replace=FALSE),] >> dat2 <- AnalysisDF_clean[sample(1:nrow(AnalysisDF_clean), >> 41,replace=FALSE),] >> >> but I have a problem because in dat2 sometimes there are some value present >> in dat1. >> >> thanks >> >> Gianni >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-Geo mailing list >> [email protected] >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> >> > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > [email protected] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- -- Wilfried Thuiller Laboratoire d'Ecologie Alpine, UMR-CNRS 5553 Université J. Fourier BP 53, 38041 Grenoble Cedex 9, France Tel: +33 (0)4 76 63 54 53 Fax: +33 (0)4 76 51 42 79 Email: [email protected] Home page: http://www.will.chez-alice.fr Website: http://www-leca.ujf-grenoble.fr/equipes/tde.htm FP6 European MACIS project: http://www.macis-project.net FP6 European EcoChange project: http://www.ecochange-project.eu [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
