jeudi 21 octobre 2021

Randomly delete rows due to a variable in a dataframe

In my data below, I wonder how to delete all rows with a given value of outcome from n randomly selected studyies?

The only condition is that such a deletion should not be done if a study would be completely deleted from data.

For example, below let's say the given value of outcome is "A". Then, for a given n (say n = 1), we delete all rows with with outcome == "A" from 1 randomly selected study subject to the condition that that randomly selected study won't be completely deleted from data.

Is this possible in R?

m =
  "
  study group outcome 
1     1     1       A   
2     1     1       B    
3     1     2       A 
4     1     2       B 
5     2     1       A   
6     2     1       B    
7     2     2       A 
8     2     2       B
9     3     1       B
9     3     1       B  
"  
data <- read.table(text=m,h=T)



Aucun commentaire:

Enregistrer un commentaire