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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:38:05+00:00 2026-06-09T08:38:05+00:00

I have data with 3 relevant variables: The first is an activity (x1), the

  • 0

I have data with 3 relevant variables: The first is an activity (x1), the second is the respondents rating of that activity (x2), and the third is the proper name of the activity in x1 (x3). The x1 variables are respondent written, and very close matches to the reference variable of the activity x3, but all a little bit different. I would like to match and replace all x1’s with the reference x3 – I was thinking of using a loop referring to each reference activity x3 and replacing the x1 respondent written activity using a program like agrep. However, agrep seems only to tell me what the matches are. How can I replace the x1 variables with the “correct” string title in x3?

  • 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-06-09T08:38:06+00:00Added an answer on June 9, 2026 at 8:38 am

    in R, the function agrep returns the indices where it found a match, not the number of matches

    agrep('chrg', c('charge', 'trapper', 'friend', 'charger'))
    # [1] 1 4
    

    If you would like to have the value instead of the index, you can pass value=TRUE.

    agrep('chrg', c('charge', 'trapper', 'friend', 'charger'), value=TRUE)
    # [1] "charge"  "charger"
    

    EDIT after your update:

    If x1 and x3 are in phase (for each index you have the names of the same activity) here is a snippet that will do the trick.

    subs <- function(x, old, new) {
        # Replace 'old' by 'new' in 'x'.
        matchv <- match(x, old, nomatch=0)
        replace(x, matchv > 0, new[matchv])
    }
    # y is any vector that contains short names.
    subs(y, x1, x3)
    

    If they are not in phase you can create the old and new vectors as follows with agrep.

    oldnew <- sapply(x1, function(x) { agrep(x, x3, value=TRUE)[1] })
    subs(y, names(oldnew), oldnew)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am importing data from MySQL to PowerPivot. I have all of the relevant
I have data-segment attribute in my body tag that is changed by a slider.
I have data from two different sources that I need to combine. Some data
I have the following function that draws some data from a chi-squared distribution and
i have data-grid in my application and i want to customize my data-grid so
I have 'data.xlsx' file with cells of numbers and letters. when I run this
I have data from travel diaries which has been read in from a csv
I have data coming from an external system (in CSV form). The data contains
I have data like the following: var data = [{ id: 1, date: new
I have data stored in three columns of Excel Column A: Serial Number Column

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.