Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6119345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:32:31+00:00 2026-05-23T15:32:31+00:00

I am working with some US govt data which has a lengthy list of

  • 0

I am working with some US govt data which has a lengthy list of cities and zip codes.
After some work, the data is in the following format.

dat1 = data.frame(keyword=c("Bremen", "Brent", "Centreville, AL", "Chelsea, AL", "Bailytown, Alabama", "Calera, Alabama",
              "54023", "54024"), tag=c(rep("AlabamCity",2), rep("AlabamaCityST",2), rep("AlabamaCityState",2), rep("AlabamaZipCode",2)))
dat1

However, there are certain keywords which aren’t properly working. So in the below example, there are two ‘zip codes’ which
are labeled as ‘AlabamaCity’ and ‘AlabamaCityState’. For some reason, the original data set from the government has several zipcodes
which aren’t properly grouped with the other zip codes.

dat2 = data.frame(keyword=c("Bremen", "Brent", "50143", "Chelsea, AL", "Bailytown, Alabama", "52348",
              "54023", "54024"), tag=c(rep("AlabamCity",2), rep("AlabamaCityST",2), rep("AlabamaCityState",2), rep("AlabamaZipCode",2)))
dat2

I wanted to know how I could iterate through the entire list of keywords and delete all the rows with numeric values (they’re acctually saved as character
values) which don’t have a ‘AlabamaZipCode’ tag. So the previous data should end up looking like.

dat3 = data.frame(keyword=c("Bremen", "Brent", "Chelsea, AL", "Bailytown, Alabama", "54023", "54024"), 
          tag=c(rep("AlabamCity",2), rep("AlabamaCityST",1), rep("AlabamaCityState",1), rep("AlabamaZipCode",2)))
dat3

The challange seems to be that there are certain numeric values which I want to keep and others which I want to delete.
Can anyone help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:32:31+00:00Added an answer on May 23, 2026 at 3:32 pm

    I think two grepl expressions should do the trick:

    > dat2[ !( grepl("City", dat2$tag) &  grepl("^\\d", dat2$keyword) ) , ]
                 keyword              tag
    1             Bremen       AlabamCity
    2              Brent       AlabamCity
    4        Chelsea, AL    AlabamaCityST
    5 Bailytown, Alabama AlabamaCityState
    7              54023   AlabamaZipCode
    8              54024   AlabamaZipCode
    

    You are eliminating the rows where there are digits in keyword and “City” in tag

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on some code today, I found that the following would work in 5.3,
i am working on some camera data. I have some points which consist of
After working on some test code for open ID authentication, I had a break
I`m working on some sql queries to get some data out of a table;
I've created a simple Facebook Reveal tab, which was working some time ago until
Working on some legacy hibernate code. How do I do the following with hbm.xml(hibernate
I'm working with some UK postcode data around 60,000 entries in a SQL 2008
I am working on some legacy code, and I have the following wonderful issue.
Am working on some application. However, i have finished two modules which invoke the
I am working on some bash scripts that I'd like to work across my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.