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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:49:30+00:00 2026-05-30T03:49:30+00:00

I am a complete newbie with R and I ask for your help. I

  • 0

I am a complete newbie with R and I ask for your help.

I have a data frame DF like this:

user      age    email        address   ...
user1     20     u1@domain    address1  ...
user2     19     u2@domain    address2  ...
user3     30     u3@domain    address3  ...
...
userm     32     um@domain    addressm ...
...
usern     xx     un@domain    address4  ...

I have a vector as following:

user1
user3
...
userm

I need to have the following:

user      age    email        address   newcol ...
user1     20     u1@domain    address1  yes    ...
user2     19     u2@domain    address2  no     ...
user3     30     u3@domain    address3  yes    ...
...
userm     32     um@domain    addressm  yes    ...
...
usern     xx     un@domain    address4  no     ...

In short, add a new column to DF containing no (as default) and yes if the correspondent user is in the vector.

Any advise is appreciated,
Thanks for your time.

  • 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-30T03:49:32+00:00Added an answer on May 30, 2026 at 3:49 am

    To expand on Joran’s answer:

    Assuming your data.frame is named df. Make a new column in your data.frame called newcol:

    df$newcol <- 'no'
    

    Then change the values in newcol to ‘yes’ if they’re %in% your vector (I’m assuming its named vec).

    df$newcol[df$user %in% vec] <- 'yes'
    

    You could also do this in one step using ifelse:

    df$newcol <- ifelse(df$user %in% vec, 'yes', 'no')
    

    Or if you wanted to get tricky you could use merge(..., all=TRUE)…

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

Sidebar

Related Questions

I'm a complete rails newbie, so forgive me if this is trivial. I have
Forgive the complete newbie question here - I know this is really basic stuff,
I am complete newbie for programming and this is my first real program I
I am complete newbie in mod_rewrite , and I have been going through some
Sorry, I'm not even sure how to ask, since I'm a complete newbie at
I am a complete newbie to SSIS. I have a c#/sql server background. I
I'm a complete newbie when it comes to servers, so I need some help.
I'm a complete newbie in ruby but I can feel that this code can
WARNING: Complete newbie to RoR and Ruby alert! * I have a login method
I'm a complete newbie to C# so excuse me if this looks weird. I

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.