0

I'm not understanding what the error is as the tidy function works fine with other shapefiles, is USAboundaries missing something?

library(USAboundaries)
library(broom)

states_dat <- tidy(us_states(), region = "geoid")

##> states_dat <- tidy(us_states(), region = "geoid")
##Error in psych::describe(x, ...) : unused argument (region = "geoid")

head(us_states()[4],3)

##> head(us_states()[4],3)
##   geoid
##1     23
##2     15
##3     04
SCDCE
  • 1,603
  • 1
  • 15
  • 28
  • I don't know the `tidy()` function, but for what I can see the column names goes to one column named "column", and the other columns are some statistics of theses variables... Is this correct? – cirofdo May 24 '18 at 17:54

1 Answers1

1

us_states() returns an sf object. tidy has no method for sf objects and uses the data.frame method instead. On the other hand, tidy has methods for a variety of classes from the sp package, which may be why it "works fine with other shapefiles." (See help(sp_tidiers).)

To use your existing code, you can convert the us_states() output to a Spatial object:

library(sf)
states <- as(us_states(), "Spatial")
states_dat <- tidy(states, region = "geoid")

To learn how to work with sf objects in a tidy framework, you may find http://strimas.com/r/tidy-sf/ helpful.

Weihuang Wong
  • 12,868
  • 2
  • 27
  • 48