Reputation: 1
im trying to run this code but i keep getting this error, given the code below, Im applying inner-join for 2 lists which are student_db and grade_db by student_id and then couse_db by course_id.
could anyone help with this issue?
q2 <- inner_join(student_db, grade_db, by = "student_id") %>%
inner_join(course_db, by = "course_id", suffix = c(".student", ".course")) %>%
filter(name.student == "Ava Smith" | name.student == "Freddie Haris")
Error in common_by.list()
:
! by
can't contain join column
course_id
which is missing from LHS.
Run rlang::last_error()
to see where the error occurred.
Upvotes: 0
Views: 447
Reputation: 1429
Does this work?
library(dplyr)
q2 <- student_db %>%
inner_join(grade_db, by = c("student_id"="student_id")) %>%
inner_join(course_db, by = c("course_id"="course_id")) %>%
filter(name.student %in% c("Ava Smith","Freddie Haris"))
If the names of your id variables are different in the two data frames, the by
argument allows you to tell R which variables should matched, e.g. by=("var_from_df1"="var_from_df2")
. (My guess is your dataframes have different column names, so this might be what you need to fix....
I'm not sure why you've included the suffix
argument. That's there for if you have two variables with same name in both data sets with data that doesn't match. If you need it you can add it back. It's hard to tell exactly what the problem is without seeing your dataframes or similar example data....
Upvotes: 0