Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

results aren't stored properly, why?

I don’t get it why it doesn’t store the results properly in the vector.

I only see the comment: numeric (empty), I’ve read about it on Stackflow and tried the solutions but can’t fix my problem.

Is there a solution for it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Would be very nice if somebody could help me out.

a <- c(100,101,102,100)
return1 <- diff(a)/a[-length(a)]


zz <- c()

for (i in return1){
  zz[i]<- 100*(i+1)+100
  
}

>Solution :

EDIT:
If you want to store values in zz, the index i in zz[i] should be an integer of length 1:length(return1).

Because return1 contains non-rounded numbers, this condition is not satisfied. You can solve around this by introducing a proper index that equals 1 in the first iteration and increases 1 unit with each subsequent iteration.

Hence, the following should work:

a <- c(100,101,102,100)
return1 <- diff(a)/a[-length(a)]

zz <- c()
count <- 0
for (i in return1){
  count <- count + 1
  zz[count]<- 100*(i+1)+100
  
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading