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 7194295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:20:33+00:00 2026-05-28T20:20:33+00:00

I am working on a large dataset, an example of which is shown below:

  • 0

I am working on a large dataset, an example of which is shown below:

Df1 <- data.frame(ID = c(1:7),                    
              home_pc = c("VB2 4RF","CB4 2DT", "NE5 7TH", "BY5 8IB", "DH4 6PB","MP9 7GH","KN4 5GH"),
              start_pc = c(NA,"Home", "FC5 7YH","Home", "CB3 5TH", "BV6 5PB",NA),
              end_pc = c(NA,"CB5 4FG","Home","Home","Home","GH6 8HG",NA))

I want to do two things:

  1. Firstly, delete rows which have an NA in the columns “start_pc” and “end_pc”.
  2. When “Home” is written in either the “start_pc” or “end_pc” columns, I want to be able to replace this with the postcode in “home_pc”.

How is best to tackle this problem – could anyone give me any ideas how best to do this?

Many thanks.

  • 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-28T20:20:34+00:00Added an answer on May 28, 2026 at 8:20 pm

    okay here’s one starting point – others will surely give you more elaborate answers.

    First, getting rid of NA values:

      Df1 <-  na.omit(Df1)
    

    this will do the job for all columns in the data.frame object

    Second, replacing the start and end columns. try the ifelse() function which is vectorised:

    Df1 <- within(Df1, 
    {
      start_pc <- ifelse(start_pc == 'Home', home_pc, start_pc)
      end_pc <- ifelse(end_pc == 'Home', home_pc, end_pc)
    })
    

    hope i understood your question correctly! Some additional comments: if you want to prove if something is NA (e.g. within the ifelse() function) use is.na() the opposite is !is.na(). You may also build subsets of the dataframe with this: subset(Df1, !is.na(home_pc)) should work for example. Of course check out the help file for all these functions if you need some more hints: ?ifelse or ?subset etc.

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

Sidebar

Related Questions

I am working on a large dataset which comprises travel behaviour data over a
Im working with a large dataset of point of interest (POI) which all have
I have two tables: p_group.full_data, which is a large dataset I'm working on (100k
I am working on a large dataset analysing survey data. From the data, I
I am working on a project which will be using large datasets (both 2D
We are working with large amounts of data, all tagged in UTC (in Java).
Working with a relatively large data set I have a situation where I need
I'm working with a large hierarchical data set in sql server - modelled using
I've inherited a large project which uses Office.Interop.Excel to insert data into a spreadsheet.
I am working on a large dataset showing how people travel. I need to

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.