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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:50:13+00:00 2026-06-14T15:50:13+00:00

Folllow up on question Searching for unique values in dataframe and creating a table

  • 0

Folllow up on question Searching for unique values in dataframe and creating a table with them

Here is how my data looks like

    UUID    Source
1   Jane    http//mywebsite.com44bb00?utm_source=ADW&utm_medium=banner&utm_campaign=Monk&gclid1234
2   Mike    http//mywebsite.com44bb00?utm_source=Google&utm_medium=cpc&utm_campaign=DOG&gclid1234
3   John    http//mywebsite.com44bb00?utm_source=Yahoo&utm_medium=banner&utm_campaign=DOG&gclid1234
4   Sarah   http//mywebsite.com44bb00?utm_source=Facebookdw&utm_medium=cpc&utm_campaign=CAT&gclid1234
5   Michael http//mywebsite.com44bb00?utm_source=Twitter&utm_medium=GDNr&utm_campaign=CAT&gclid1234
6   Bob     http//mywebsite.com44bb00?utm_source=ADW&utm_medium=GDN&utm_campaign=DOG&gclid1234
7   Mark    http//mywebsite.com44bb00?utm_source=Twitter&utm_medium=banner&utm_campaign=MONK&gclid1234
8   Anna    http//mywebsite.com44bb00?utm_source=Facebook&utm_medium=banner&utm_campaign=MONK&gclid1234

And here is the desired output of what I am trying to achieve

    NAME    UTM_SOURCE  UTM_MEDIUM  UTM_CAMPAIGN
1   Jane    ADW             banner     Monk
2   Mike    Google          cpc        DOG
3   John    Yahoo           banner     DOG
4   Sarah   Faceboo         cpc        CAT
5   Michael Twitter         GDN        CAT
6   Bob     ADW             GDN        DOG
7   Mark    Twitter         banner     MONK
8   Anna    Facebook        banner     MONK

So in other words what I want is to obtain a specific piece of information based on a criteria. Example: search in the dataframe for the value “utmsource=” and when found, copy whatever information is found between the “=” and “&” signs. In the case of User no1 (Jame) if you look in the original file, her Source URL contains the value “utm_source=ADW”. In the output file, the “ADW” bit is extracted and imputed in a new column named “utm_source”. Same principle for all other users and other dimmensions (utm_medium & utm_campaign)

I understand that the function gsub can help me. Here is what I have tried so far:

> file1 <- read.csv("C:/Users/Dumitru Ostaciu/Desktop/Users.csv")
> file1 <- transform(file1, Source = as.character(Source))
> file2 <- gsub(".*\\?utm_source=", "", file1$Source)

And this is the result I got

  UUID  SOURCE
    1   ADW&utm_medium=banner&utm_campaign=Monk&gclid1234
    2   Google&utm_medium=cpc&utm_campaign=DOG&gclid1234
    3   Yahoo&utm_medium=banner&utm_campaign=DOG&gclid1234
    4   Facebookdw&utm_medium=cpc&utm_campaign=CAT&gclid1234
    5   Twitter&utm_medium=GDNr&utm_campaign=CAT&gclid1234
    6   ADW&utm_medium=GDN&utm_campaign=DOG&gclid1234
    7   Twitter&utm_medium=banner&utm_campaign=MONK&gclid1234
    8   Facebook&utm_medium=banner&utm_campaign=MONK&gclid1234   

I have 2 questions about this:

1) In the output that I got, the function copied everything that followed the value “utm_source-” . How do I add another dimension to make the formula copy only what is between “=” and “&”

2) How do i keep the values that were initially in the first column (UUID) , Jane, Mike, John, etc?

  • 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-14T15:50:14+00:00Added an answer on June 14, 2026 at 3:50 pm

    You need to do two things:

    1. Use gsub to strip the website name from your Source
    2. Use strsplit to separate the remaining string at each occurrence of ?

    Read in the data:

    x <- read.table(text="
    UUID    Source
    1   Jane    http//mywebsite.com44bb00?utm_source=ADW&utm_medium=banner&utm_campaign=Monk&gclid1234
    2   Mike    http//mywebsite.com44bb00?utm_source=Google&utm_medium=cpc&utm_campaign=DOG&gclid1234
    3   John    http//mywebsite.com44bb00?utm_source=Yahoo&utm_medium=banner&utm_campaign=DOG&gclid1234
    4   Sarah   http//mywebsite.com44bb00?utm_source=Facebookdw&utm_medium=cpc&utm_campaign=CAT&gclid1234
    5   Michael http//mywebsite.com44bb00?utm_source=Twitter&utm_medium=GDNr&utm_campaign=CAT&gclid1234
    6   Bob     http//mywebsite.com44bb00?utm_source=ADW&utm_medium=GDN&utm_campaign=DOG&gclid1234
    7   Mark    http//mywebsite.com44bb00?utm_source=Twitter&utm_medium=banner&utm_campaign=MONK&gclid1234
    8   Anna    http//mywebsite.com44bb00?utm_source=Facebook&utm_medium=banner&utm_campaign=MONK&gclid1234", header=TRUE, stringsAsFactors=FALSE)
    

    Use strsplit to separate the Source string at each ?:

    z <- matrix(
      unlist(strsplit(gsub(".*\\?", "", x$Source), "\\&")), 
      ncol=4, byrow=TRUE)
    cbind(x$UUID, gsub(".*=", "", z))
    
         [,1]      [,2]         [,3]     [,4]   [,5]       
    [1,] "Jane"    "ADW"        "banner" "Monk" "gclid1234"
    [2,] "Mike"    "Google"     "cpc"    "DOG"  "gclid1234"
    [3,] "John"    "Yahoo"      "banner" "DOG"  "gclid1234"
    [4,] "Sarah"   "Facebookdw" "cpc"    "CAT"  "gclid1234"
    [5,] "Michael" "Twitter"    "GDNr"   "CAT"  "gclid1234"
    [6,] "Bob"     "ADW"        "GDN"    "DOG"  "gclid1234"
    [7,] "Mark"    "Twitter"    "banner" "MONK" "gclid1234"
    [8,] "Anna"    "Facebook"   "banner" "MONK" "gclid1234"
    

    And then convert to a data frame and add names:

    z <- matrix(
      unlist(strsplit(gsub(".*\\?", "", x$Source), "\\&")), 
      ncol=4, byrow=TRUE)
    z <- cbind(x$UUID, gsub(".*=", "", z))
    z <- as.data.frame(z[, -5])
    names(z) <- c("UUID", "UTM_SOURCE", "UTM_MEDIUM", "UTM_CAMPAIGN")
    z
    
         UUID UTM_SOURCE UTM_MEDIUM UTM_CAMPAIGN
    1    Jane        ADW     banner         Monk
    2    Mike     Google        cpc          DOG
    3    John      Yahoo     banner          DOG
    4   Sarah Facebookdw        cpc          CAT
    5 Michael    Twitter       GDNr          CAT
    6     Bob        ADW        GDN          DOG
    7    Mark    Twitter     banner         MONK
    8    Anna   Facebook     banner         MONK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Follow-Up-Question to How to change LINQ O/R-M table name/source during runtime? ) I need
This is a follow-on question from the one I asked here . Can constraints
I know how that question looks, but I'm quite serious. I am trying to
I have been searching for an answer to this question for days and it
A follow up to my (flop of a) question(!), here . As said in
I have a follow up question on the accepted answer given here: Two models
This is a follow-up on a previous question of mine regarding searching in lists
Disclaimer: I know this type of question has been asked here before, I just
This is a follow up question to the one answered here: Excluding dates from
This is a follow up question from here . I have some output and

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.