Split data into N equal groups I have a dataframe which contains values across 4 columns: 
For example:ID,price,click count,rating
What I would like to do is to "split" this dataframe into N different groups where each group will have equal number of rows with same distribution of price, click count and ratings attributes. 
Any advice is strongly appreciated, as I don't have the slightest idea on how to tackle this !
 A: Edit: The minDiff package has been superceded by the anticlust package.

This is a very late answer, but I found this page while googling whether
the problem as stated has ever been discussed anywhere. Maybe my answer
will help if someone finds this page from now on.
I wrote an R package, which does exactly what the question
asked for: it takes a data.frame and creates N different groups while
trying to minimize the differences between groups in one or several
criteria. It uses a simple method based on repeated random
assignment, which is also the suggested method in the approved response.
This is the link to the package minDiff:
To tackle the stated problem, you could use:
library(minDiff)
assigment <- create_groups(dataframe, criteria_scale = c("price", "click count", "rating"), sets_n = N, repetitions = 1000)

The repetitions argument will determine how often you randomly create
different groups. The best assignment - the one that has minimal
differences between groups - will be returned.
A: Although Alex A's answer gives an equal probability for each group, it does not meet the question's request for the groups to have an equal number of rows. In R:
stopifnot(nrow(df) %% N == 0)
df    <- df[order(runif(nrow(df))), ]
bins  <- rep(1:N, nrow(df) / N)
split(df, bins)

A: This can be solved with nesting using tidyr/dplyr
require(dplyr) 
require(tidyr)

num_groups = 10

iris %>% 
   group_by((row_number()-1) %/% (n()/num_groups)) %>%
   nest %>% pull(data)

A: If I understand the question correctly, this will get you what you want. Assuming your data frame is called df and you have N defined, you can do this:
split(df, sample(1:N, nrow(df), replace=T))

This will return a list of data frames where each data frame is consists of randomly selected rows from df. By default sample() will assign equal probability to each group.
