Yes, you can install Rank Math. It will deactivate Yoast SEO and automatically import the required data from the Yoast SEO plugin. You will not lose any optimization you have done using the Yoast SEO plugin.