-1

When I perform an inner join, it seems to work but then when I try and call the new table to use in R i get the following error:

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

shahaf
  • 4,750
  • 2
  • 29
  • 32
jam.gunn
  • 21
  • 2
  • 1
    Please provide data and your code. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – yusuzech Oct 04 '19 at 16:39
  • I can't repost the code or table names as they're sensitive, but I'm using odbc to connect to the server through R, then write an inner join with a WHERE statement to filter on date. Then select the columns which I want to call – jam.gunn Oct 04 '19 at 17:13
  • 2
    You can 1. encrypt your data, 2. provide only a sample of your data, or 3. create an example data which has the same structure as your data. We can't help with a single error message. – yusuzech Oct 04 '19 at 17:16
  • At the least it should be possible to share the relevant few lines of code, replacing any sensitive information (table names, passwords, etc.) with placeholders. – Jon Spring Oct 04 '19 at 18:59

1 Answers1

2

In the absence of any code of sample data, I am assuming that you are not using some of the functionality provided by the tidyverse package.

Specifically, the dplyr package, which is part of the Tidyverse, contains the functions to be able to join data together quickly and easily. However, the R syntax is not the same as the SQL syntax. Most notably, you can successfully run the inner_join() function without using the select_() function.

Take a look at my below code. You'll see that in the data I have created, I've joined two data frames together (NameCity and CityState) by using the inner_join() function. You will see the final result shows only four rows, which is the matching records between the two data frames.

Check out this link for details about using SQL joins in your R code: Join two tbls together.

> # Load libraries
> library(dplyr) #For the inner_join() function

> # Load the data frames
> NameCity <- data.frame(id=c(1,2,3,4,5),
+                        name=c("NameOne","NameTwo","NameThree","NameFour","NameFive"),
+                        city=c("Sydney","Sydney","Melbourne","Adelaide","Brisbane"),
+                        stringsAsFactors=F)

> CityState <- data.frame(id=c(1,2,3),
+                         city=c("Sydney","Melbourne","Brisbane"),
+                         state=c("NSW","VIC","QLD"),
+                         stringsAsFactors=F)

> # Inspect the data frames
> NameCity
    id      name      city
[1]  1   NameOne    Sydney
[2]  2   NameTwo    Sydney
[3]  3 NameThree Melbourne
[4]  4  NameFour  Adelaide
[5]  5  NameFive  Brisbane

> CityState
    id      city state
[1]  1    Sydney   NSW
[2]  2 Melbourne   VIC
[3]  3  Brisbane   QLD

> # Join the data together
> AllTogether <- inner_join(NameCity[,c("name","city")],
+                           CityState[,c("city","state")],
+                           by="city")

> # Inspect the final frame
> AllTogether
         name      city state
[1]   NameOne    Sydney   NSW
[2]   NameTwo    Sydney   NSW
[3] NameThree Melbourne   VIC
[4]  NameFive  Brisbane   QLD

I trust that helps.

chrimaho
  • 580
  • 4
  • 22