R for loop to populate new variable -


dear stackoverflow community,

i @ loss loop , i'm pretty sure minor problem. did browse through loop questions have been asked...

here have far:

xvals <- as.matrix(seq(1,10, 1)) 

i create ovals based on ovals

yvals <- (i in 1:nrow(xvals)){   p <- 2.69/(1+2.69)   if (i == 1){     yvals[i,] <- round(p, 2)}   else {     yvals[i,] <- round(1-(p)^i, 2)} } 

unfortunately, thing keeps throwing error

error in 1:nrow(xvals) : argument of length 0 

when change xvals matrix, different error:

error in yvals[i, ] <- round(p, 2) :    incorrect number of subscripts on matrix 

without loop

xvals <- 1:10 p <- 2.69/(1+2.69) yvals <- 1-p^xvals yvals[1] <- p yvals <- round(yvals, 2) 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -