vendredi 5 novembre 2021

Is that possible to get the index of unselected rows of data frame in R?

I want the indices of the unselected rows when using sample() in R. Consider the following case.

df <- data.frame(id = c(1,1,2,2,3,3),
                 v1 = c(2,2,9,4,7,1),
                 v2 = c(3,5,8,5,8,5))
ss  <- ceiling(0.5*nrow(df)) #size
set.seed(123)
rid <- sample(seq_len(nrow(df)),size=ss,replace=F)

Now, the rows 3,6,2 are randomly selected. Is there a way to know indices of unselected rows (1,4,5)?

Thanks!




Aucun commentaire:

Enregistrer un commentaire