0

I have an excel spreadsheet that I created from data on this site https://www.ucrdatatool.gov/Search/Crime/State/RunCrimeStatebyState.cfm

It is Crime statistics of the US by state from 1970 - 2000. I need a way to separate each state into it's own tibble.

I tried using read_excel() with these parameters: "CrimeStatebyState.xlsx" range=10:41 but I got this error :

Error in UseMethod("as.cell_limits") : 
  no applicable method for 'as.cell_limits' applied to an object of class "c('integer', 'numeric')"

I have tried :

Alabama <- split(Crime_US, cell_rows(10:41))

and received this error: data length is not a multiple of split variable

Jay Wehrman
  • 193
  • 2
  • 10
  • 2
    That is not how you define the `range`, as is well documented. `?read_excel` refers to `?cell-specification`. Nonetheless, you are probably goint to be better off just reading in the whole thing, and then running something like `split(my_df, my_df$state)`. [Here](https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames/24376207#24376207) is a good reference answer. – Axeman Nov 27 '19 at 01:44
  • I should have been more clear. I am actually trying to split by rows not columns. It doesn't look like the split() function will work for me. – Jay Wehrman Nov 27 '19 at 02:46
  • Yes, I know, like `split(iris, iris$Species)`, try it out. – Axeman Nov 27 '19 at 02:48
  • wouldn't iris$Species be a column? There is no real separation in this large dataframe that i can easily identify and grab. just rows of whitespace. – Jay Wehrman Nov 27 '19 at 03:01
  • There is not `State` column? If you really need to read in separately, you'd need to use `cell_rows(10:41)`, instead of `10:41` as the range argument, as found in the help I indcated. – Axeman Nov 27 '19 at 03:15
  • I tried using cell_rows, but my list was empty and I received a warning in r. post has been edited above to reflect that. – Jay Wehrman Nov 27 '19 at 03:36
  • No, `cell_rows` would be in `read_excel` command. `split` would need a column to split by, or you need to give us an actual reproducible example. – Axeman Nov 27 '19 at 03:52

1 Answers1

-1

it's slice(), the function that subsets a dataframe. it's slice().

Jay Wehrman
  • 193
  • 2
  • 10