boop - 4 months ago 18

R Question

I have two data frames in R.

`data`

While

`averages`

What I'd like to do is add a column to

`data`

`averages`

`avg`

`for(j in 1:nrow(avgs)){`

for(i in 1:nrow(data)){

if(identical(data[i,4], averages[j,1])){

gd[i,10] <- avgs[j,3] } } }

After running the loop, the

`avg`

`data`

`if(identical(data[i,4], averages[j,1]))`

`FALSE`

Answer

Are you looking for `merge`

function?

```
merge(x = data, y = avgs, by = "departmentName", all.x=TRUE)
```