mardi 25 avril 2017

R: How to get my for loop to print a vector

I need my for loop to output a vector instead of just a series of answers. Here is my code:

mean=211
sd=sqrt(558)
x=rnorm(100,mean,sd)
cost=40

for(i in c(1:100))
{
    if(x[i]<=200)
    {
        profit=x[i]-cost
    }
    else
    {
        profit=200-cost
    }
print(profit)
}

How do I get it to print the different profits as one vector?

Aucun commentaire:

Enregistrer un commentaire