-3

Here is my code

for(j in 1:423){
for(i in 1:18){
kh[j,i+1] <- kh[j,i] + kh[j,i+1]
if(kh[j,i+1]>kh$median[j]){break}}print(i+1)}

I don't know why this code won't work, yet this code works well:

for(i in 1:18){
kh[1,i+1] <- kh[1,i] + kh[1,i+1]
if(kh[1,i+1]>kh$median[1]){break}}
print(i+1) 

I want to result about every J's (from 1 to 423) Please help me !

Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • 1
    Welcome to Stack Overflow! Can you please include data and/or code that will provide us with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? – Ben Bolker Aug 09 '16 at 01:46

1 Answers1

1

It's because you didn't use proper syntax and thus confused R.

After {break}}

You must either have a ; or start a new line before

print(i+1)}

Otherwise R does not understand that print is a function you're trying to run.

Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • 1
    Thank you so much! – Kyung hwan Aug 09 '16 at 01:55
  • @Kyunghwan Glad to help :) Please mark this as the answer (the green check mark) if this solves your problem. – Hack-R Aug 09 '16 at 01:56
  • StackOverflow deprecates [using comments to say "thank you"](http://meta.stackoverflow.com/questions/258004/should-thank-you-comments-be-flagged?lq=1); if this answer was useful you can upvote it (if you have sufficient reputation), and in any case if it answers your question satisfactorily you are encouraged to click the check-mark to accept it. – Ben Bolker Aug 09 '16 at 02:10