Could be a few things or a combination
- Problem with RStudio configuration
- Problem with R version
- Problem with macOS configuration
- Problem with MacAir hardware
To check 1. run the same code in the R app from the Terminal app. This doesn't involve RStudio at all. If the code is also slow in the R app, it suggests that RStudio isn't the problem, and you should check the R version from the terminal R --version It should be version 4.0 or above. That also covers item no. 2.
If the R app session is not also slow, check the RStudio configuration from the menu `Tools | Global | Options | General Advanced against the image below
If necessary and you are able, write and compile a similar program in another language and see if it also runs too slowly. If that is the case, it could be either an OS problem or a hardware problem and seeking help in a macOS - specific forum might be necessary.