Sample using start and end values within a loop in R

前端 未结 3 2052
庸人自扰
庸人自扰 2021-01-27 05:31

I am trying to sample between a range of values as part of a larger loop in R. As the loop progresses to each row j, I want to sample a number between the value giv

3条回答
  •  旧巷少年郎
    2021-01-27 05:56

    Figured it out. df[j,4] <- mapply(function(x, y) sample(seq(x, y), 1), df[j,"start"], df[j,"end"])

    I just needed to be specific as to which row of the sampled values I wanted to enter into df[j,4]. Specifying row j for columns start and end did the trick.

提交回复
热议问题