R repeat function until condition met

前端 未结 4 2008
别那么骄傲
别那么骄傲 2020-12-23 22:32

I am trying to generate a random sample that excludes certain \"bad data.\" I do not know whether the data is \"bad\" until after I sample it. Thus, I need to make a rando

4条回答
  •  温柔的废话
    2020-12-23 23:38

    use this after your first sample

    while (any(bad <- (x$SCORE <= 0)))
       x[bad, ] <- df[sample(nrow(df), sum(bad)), ]
    

提交回复
热议问题