Mauricio Rostagno Asked: 2022-08-31 05:28:25 +0800 CST 2022-08-31 05:28:25 +0800 CST 2022-08-31 05:28:25 +0800 CST How to split a table into two random subtables with the same number of rows? 772 I am trying to do this with the "iris" table but I am not understanding how to order the terms. Some kind help please. r 1 Answers Voted Best Answer Isaac 2022-08-31T06:39:04+08:002022-08-31T06:39:04+08:00 I hope I understood the question, and maybe you can try the following: # Definir el número de dataframes que quieres: n <- 2 # Split el dataframe en dos y guardar el resultado como una lista de objetos: df1 <- split(iris, factor(sort(rank(row.names(iris))%%n))) # Examinar el objeto: df1 %>% str() List of 2 $ 0:'data.frame': 75 obs. of 5 variables: ..$ Sepal.Length: num [1:75] 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... ..$ Sepal.Width : num [1:75] 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... ..$ Petal.Length: num [1:75] 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... ..$ Petal.Width : num [1:75] 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... ..$ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ... $ 1:'data.frame': 75 obs. of 5 variables: ..$ Sepal.Length: num [1:75] 6.6 6.8 6.7 6 5.7 5.5 5.5 5.8 6 5.4 ... ..$ Sepal.Width : num [1:75] 3 2.8 3 2.9 2.6 2.4 2.4 2.7 2.7 3 ... ..$ Petal.Length: num [1:75] 4.4 4.8 5 4.5 3.5 3.8 3.7 3.9 5.1 4.5 ... ..$ Petal.Width : num [1:75] 1.4 1.4 1.7 1.5 1 1.1 1 1.2 1.6 1.5 ... ..$ Species : Factor w/ 3 levels "setosa","versicolor",..: 2 2 2 2 2 2 2 2 2 2 ...
I hope I understood the question, and maybe you can try the following: