Relatively new to R and I haven't been able to find online what would be the equivalent of a SQL left join
. Let's say I have data that looks like:
School| Year| Grade | #students | math_approached| math_metorexceeded
610534| 2016| Mathematics Grade 3| 57 | 5.3% | 94.7%
610534| 2016| Mathematics Grade 4| 60 | 8.3% | 91.7%
610534| 2016| Mathematics Grade 5| 59 | 6.8% | 93.2%
610534| 2015| Mathematics Grade 3| 57 | 5.3% | 94.7%
610534| 2015| Mathematics Grade 4| 60 | 8.3% | 91.7%
610534| 2015| Mathematics Grade 5| 59 | 6.8% | 93.2%
699999| 2015| Mathematics Grade 3| 51 | 5.3% | 94.7%
699999| 2015| Mathematics Grade 4| 61 | 8.3% | 91.7%
699999| 2015| Mathematics Grade 5| 53 | 6.8% | 93.2%
I'm trying to find the Math % approached value for the school grade's prior year. In SQL, this would look like
select a.*, b.math_approached, b.math_metorexceeded
from mydata as a
left join mydata as b
on a.school = b.school
and a.grade = b.grade
and b.year = '2015'
and a.year = '2016'
And back in R, I have a dataframe df
holding all the data. It has
df$school
df$year
df$grade
df$students
df$math..approached
df$math..met.or.exceeded
as its columns