0

I and new R user and wonder if you might be able to help.

I have two data frames ds and scotland. ds contains a list of the first two characters of postcodes and I want to find out which of these are postcodes in Scotland. scotland contains a list of the first two characters of Scottish postcodes.

e.g.

ds

     areaid nation
1      CO     NA
2      NE     NA
3      SA     NA
4      PR     NA
5      SK     NA
6      CF     NA
7      CM     NA
8      RG     NA
9      OX     NA
10     HG     NA
11     RM     NA
12     YO     NA
13     WR     NA
14   <NA>     NA
15      S     NA
16     BD     NA
17     TA     NA
18     SE     NA
19     SO     NA
20   <NA>     NA
21     ME     NA
22     LL     NA
23     DD     NA
24     KY     NA
25     BB     NA
26     BB     NA
27     SN     NA
28      M     NA
29     RH     NA
30     EX     NA

and scotland:

     Country areaid
1  Scotland     AB
2  Scotland     CA
3  Scotland     DD
4  Scotland     DG
5  Scotland     EH
6  Scotland     FK
7  Scotland      G
8  Scotland     HS
9  Scotland     IV
10 Scotland     KA
11 Scotland     KW
12 Scotland     KY
13 Scotland     ML
14 Scotland     PA
15 Scotland     PH
16 Scotland     TD
17 Scotland     ZE

What I'd like to do is to populate the nation column with scotland if the value in areaid$ds appears in areaid$scotland

I tried the popular soloution here but got an error message because the number of rows is different.

Thanks for any help you can offer.

Community
  • 1
  • 1
EPeas
  • 1
  • 1

0 Answers0