I need to select a random sample of one column of a R dataframe by grouping by on three other columns. This is some what similar to what has been discussed below:
and I do not know how to replicate in the Python code in R.
My bad, I haven't posted what i tried so far. I used data.table package.
library(data.table)
sample_df <- df[, .SD[sample(x = .N, size = 50)], by = id]
However, I am not sure how to sample one column by using 3 other columns as groupby
Aucun commentaire:
Enregistrer un commentaire