Lab0 Help

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Lab0 Help

brice
For the fourth question, it asks for the year that has the most toatl number of births in the U.S.. Im able to find the highest number of births by doing max(present), but this doesn't give the year that it is connected with. Has anyone found out a way to find it without just looking in the table?
Reply | Threaded
Open this post in threaded view
|

Re: Lab0 Help

Darth Knight
How about trying "which.max" command?
It will give you the index of the maximum.
Then, you could adjust this index to extract the year
by using the command in "Slicing and extracting data"
in the reference card.

There might be a better way.
Let me know if someone has another approach.


Reply | Threaded
Open this post in threaded view
|

Re: Lab0 Help

MegDawg97
In reply to this post by brice
The "which.max" command was effective. I Input which.max(present$boys+present$girls) and it output the row number correlating to the year.
Reply | Threaded
Open this post in threaded view
|

Re: Lab0 Help

brice
Yea i figured it out that same way, then you can get the year by doing "present$year[n]" where n is the value returned by "which.max(present$boys+present$girls)"