R 3.5版本无法安装state.center包的解决方法咨询
Hey there! I’ve run into this exact confusion before—let’s get you those state coordinates sorted out quickly.
Why the error pops up
First off: state.center isn’t a standalone package you can install from CRAN. It’s actually a built-in dataset included with the maps package. That’s why trying to install it directly throws that "not available" error, especially with your older R 3.5.0 version.
Step-by-step fix
Here’s how to grab your state latitude/longitude data:
Install and load the
mapspackage
Run these commands in your R console:# Install the maps package (compatible with R 3.5.0) install.packages("maps") # Load the package to access the dataset library(maps)Access the
state.centerdataset
Oncemapsis loaded, you can usestate.centerright away. It’s a list with two key vectors:state.center$x: Longitudes of U.S. state centersstate.center$y: Latitudes of U.S. state centers
Test it out with these quick checks:
# View the first 5 state coordinate pairs head(state.center) # See the full structure of the dataset str(state.center)
If you hit compatibility issues with maps
Since R 3.5.0 is quite old, the latest version of maps might not install properly. If that happens, install an older version of maps that supports R 3.5.0:
- First install the
devtoolspackage (if you don’t already have it):install.packages("devtools") - Load
devtoolsand install the compatiblemapsversion (3.3.0 works perfectly for R 3.5.0):library(devtools) install_version("maps", version = "3.3.0") - Then load
mapsand accessstate.centeras before.
Alternative for state coordinates
If you want more flexible state data (like boundary shapes or additional metadata), you could try the usmap package—just make sure to install a version compatible with R 3.5.0 if needed. But since you specifically asked for state.center, the maps package method is the direct, intended solution.
内容的提问来源于stack exchange,提问作者Alinashe

