0

I'm getting error messages trying to find summary statistics for my variables in my data sets:

**Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "character"

$ operator is invalid for atomic vectors

Error in UseMethod("tbl_vars") : no applicable method for 'tbl_vars' applied to an object of class "character"**

And to speak more to the second error message when I try to use "[" instead of the dollar symbol, to try to make it a numeric value I get the error messages:

Error in "2007"["Total Actual Costs"] <- as.numeric("2007"["Total Actual Cost"]) : 
  target of assignment expands to non-language object

and

Error in "2007"[["Total Actual Cost"]] : subscript out of bounds.

I fundamentally do not understand what's wrong, I used both an excel and CSV file. I tried changing the data value type to numerical in Excel for both of them. And I don't think that the size of the data set is a problem because I've used bigger, and I've also used much more sloppy data before so I don't think that's the issue either. I have attached all of my code below

Basically I'm trying to find a way to convert the variables into numerical format, and filter the data on FIPS code so I can have a set for both States and Counties for these years.

https://drive.google.com/open?id=1y7ISVmOKi1cWRcKNgKF7VYYNDEn0F8B1 link to my data

 ```

library(tidyselect)
library(openintro)
library(GGally)
library(dplyr)
library(e1071)
library(plotrix)
library(fastDummies)
library(ggplot2)
library(readxl)
library(tidyverse)

    '2007' <-read_xlsx("Medicare county 2007.xlsx", skip = 1)
    `2007` <- replace(`2007`,`2007` == "*",NA)
    '2008' <-read_xlsx("Medicare county 2008.xlsx", skip = 1)
    `2008` <- replace(`2008`,`2008` == "*",NA)
    '2009' <-read_xlsx("Medicare county 2009.xlsx", skip = 1)
    `2009` <- replace(`2009`,`2009` == "*",NA)
    '2010' <-read_xlsx("Medicare county 2010.xlsx", skip = 1)
    `2010` <- replace(`2010`,`2010` == "*",NA)
    '2011' <-read_xlsx("Medicare county 2011.xlsx", skip = 1)
    `2011` <- replace(`2011`,`2011` == "*",NA)
    '2012' <-read_xlsx("Medicare county 2012.xlsx", skip = 1)
    `2012` <- replace(`2012`,`2012` == "*",NA)
    '2013' <-read_xlsx("Medicare county 2013.xlsx", skip = 1)
    `2013` <- replace(`2013`,`2013` == "*",NA)
    '2014' <-read_xlsx("Medicare county 2014.xlsx", skip = 1)
    `2014` <- replace(`2014`,`2014` == "*",NA)
    '2015' <-read_xlsx("Medicare county 2015.xlsx", skip = 1)
    `2015` <- replace(`2015`,`2015` == "*",NA)
    '2016' <-read_xlsx("Medicare county 2016.xlsx", skip = 1)
    `2016` <- replace(`2016`,`2016` == "*",NA)
    '2017' <-read_xlsx("Medicare county 2017.xlsx", skip = 1)
    `2017` <- replace(`2017`,`2017` == "*",NA)

    '07state'<- filter(.data='2007','State and County FIPS Code',na.rm==TRUE)
    ```
Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • Welcome to Stack Overflow! I'm going to edit your question slightly to help it better conform to our community guidelines... OK so I was able to remove some of the extra comments and simplify the title to match our non-forum, minimalistic style but a couple of other things - we discourage cloud links for multiple reasons (security and stability) and strongly encourage MCVE's which are reproducible examples in the R tag. Cheers! – Hack-R Apr 20 '20 at 23:05
  • 1
    You are mixing up backticks and single quotes. However avoid flooding global environment with *many* data frames and instead use **one** [list of data frames](https://stackoverflow.com/a/24376207/1422451). Also, `filter` filters data frame by rows using logic which you do not have. Use `[[` for columns or `dplyr::select`. – Parfait Apr 21 '20 at 00:08
  • @Parfait Thanks you helped out, but I managed to wrangle everything into data frames and can do what I want to now – Jordan Moment Apr 22 '20 at 02:48

0 Answers0