Let's say I have the code below:
data = data.frame(x=numeric(), y=numeric(), z=numeric(), ans=numeric())
x = rnorm(10,0,.01)
y = rnorm(10,0,.45)
z = rnorm(10,0,.8)
ans = x+y+z
data = rbind(data, data.frame(x=x, y=y, z=z, ans=ans))
example = function(ans) {
ans^2
}
data$result = example(data$ans)
I want to use a while loop to assess the ans
column of the dataframe and if all of the numbers in the column are less than 0 perform the example function on the ans
column. If they are not all below 0 I would like it to run again until they are. Any help is appreciated.