This is one of the school assignment and the correct answer is already given. I thought I did okay in this but apparently my codes showing me the wrong answer. Is there anything wrong in my code?
There is nothing evidently wrong with your code, to help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
If there is nothing wrong in the code, then it is just error in the assignment! I sent him a message, I just wanted to make sure if I'm doing something wrong here since I'm merely a beginner. Thank you so much! Have a good day!
That is not what I meant, there is no evident error but since you are not sharing your data I can't test it to be sure, there is always the possibility that your code is not suitable for your data because it is in a format that requires preprocessing or some other reason I'm not considering. That is why I was asking for a reproducible example.