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"
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"
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.