I have the following function:
s_c <- function(n, t){ r_num <- runif(1,min=0,max=1) use <- sample(s[,1],1) use2 <- subset(s,s[,1]==use,2) use2 <- as.numeric(use2) ne_s <- sample(subset(s,s[,2]!=use2,2),1) Return(use) if (t>50 & r_num<0.5){ ne_s } else 0 } I would actually like to use the variable created in the function in a command outside the function, so I would like to "return" in the sense of being able to refer to the variable outside the function
Question 2:
What if I would like to do an assignment within the if statement, for example
if (t>50 & r_num<0.5){ s[,4]=use } Can this be done?