I have a simple function se <- 0.11 * (x^2) - 0.002 * x
. I want to generate two output variables se.m
and se.st
- each storing the results from 100 iterations with randomly renerated values for x
at specific intervals:
se.m <- 0.11 * (x^2) - 0.002 * x # if x[0,1]
or
se.st <- 0.11 * (x^2) - 0.002 * x # if x(1,5]
I have written this code:
my.mat <- matrix(0,100,2)
x <- runif(n = 1, min = 0, max = 5)
fuchs <- function(n){
x.m <- runif(n = 1, min = 0, max = 1)
x.st <- runif(n = 1, min = 1, max = 5)
for(i in 1:n){
print(x.m[i] <- runif(n = 1, min = 0, max = 1))
se.m <- 0.11 * (x.m^2) - 0.002 * x.m
print(x.st[i] <- runif(n = 1, min = 1, max = 5))
se.st <- 0.11 * (x.st^2) - 0.002 * x.st
}
return(list(se.m, se.st))
}
fuchs(100)
How can I store the output in two columns? I have tried using the matrix
command, but i get an error that the data is too long:
my.mat<-matrix(my.mat, se.m) Error in matrix(my.mat, se.m) : data is too long
Also the list command doesnt yield any output.
I am new to R as you can guess and would very much appriciate constructive comments/critique.