samedi 8 décembre 2018

Select rows that begin with a pattern in R

I am working with an R database. The database has 3 columns.

> head(base_sec)
        Index  NAICS    HS2
1   0.4074128   1111 010110
2   0.2858026  11111 010190
3   0.1103720  11112 010210
4  -0.8084129 111120 010290
5   0.5376827 111130 010310
6   0.6021241  11114 010391

I want to select the rows in which NAICS column meets a given condition. Specifically, I want to select the rows in which NAICS begins with any of these values:

  list=c("111","112", "113","114",
          "115", "211", "212", "213",
         "3111", "3112", "3113", "3114",
         "3115", "3116","3117", "3118",
          "3119", "321")

Any idea?

Thanks

Aucun commentaire:

Enregistrer un commentaire