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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:44:49+00:00 2026-06-14T16:44:49+00:00

Since I started using R< not long ago, I’ve found this site very useful

  • 0

Since I started using R< not long ago, I’ve found this site very useful in helping me build my scripts. I have yet again came across a challenge for which I can’t seem to find an answer anywhere. Here is my problem: In my data I have a column which contains a different URL in each row. In each of those URL’s there is a particular piece of information I want to extract. Currently I do it in excel because I’ve been told it’s impossible to do in R and that no function exists to do it.

The URL will look like this example format and it will be found in the “source” column

http://www.googleclick.com?utm_source=ADX&ID56789

http://www.googleclick.com?utm_source=ADW&ID56009

http://www.googleclick.com?utm_source=ADWords&ID53389

The part of the URL that is of importance to me is the “utm_source=ADX” bit .My data looks something like this:

User / Source

1 / http://www.googleclick.com?utm_source=ADX&ID56789

2 / http://www.googleclick.com?utm_source=ADW&ID56009

3 / http://www.googleclick.com?utm_source=ADWords&ID53389

What I need to do is to capture the utm_source from the URL and transpose the information into a different column, example below:

User / Source / utm_source

1 / googleclick / ADX&ID56789

2 / googleclick / ADW&ID56009

3 / googleclick / ADWords&ID53389

So in essence I need R to search in the entire dataframe for the value “utm_source=” and once it has found them, I want it to transpose the “utm_source=” value into a column name and to copy all the information that comes after “=” in a that column for each individual row. I know that “grep” is a function that locates a specific piece of information in the datafreme , for example data <- total[grepl(“utm_source”, total$Source), ]. This will give me all the rows that contain the word “utm_source” but what I need is the information that comes after ” utm_source”. Usually my data can have as many as 500.000 rows. At the moment I use the excel function “text to columns” for this, and I basically split the URL’s into little bits and keep the columns that I need, but this can be a very messy and lengthy process.

Is there a way to modify the grepl function to meet the criteria I need?

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

    Nothing is impossible.

    x <- read.csv(text="
    User, Source
    1, http://www.googleclick.com?utm_source=ADX&ID56789
    2, http://www.googleclick.com?utm_source=ADW&ID56009
    3, http://www.googleclick.com?utm_source=ADWords&ID53389
    ", header=TRUE, stringsAsFactors=FALSE)
    

    First, use strsplit

    strsplit(x$Source, split="\\?utm_source=")
    [[1]]
    [1] " http://www.googleclick.com" "ADX&ID56789"                
    
    [[2]]
    [1] " http://www.googleclick.com" "ADW&ID56009"                
    
    [[3]]
    [1] " http://www.googleclick.com" "ADWords&ID53389" 
    

    Then find a red-hot poker and stick in the eye of your so-called advisor.


    EDIT:

    As suggested by Paul Hiemstra, you can also use a regular expression directly:

    gsub(".*\\?utm_source=", "", x$Source)
    [1] "ADX&ID56789"     "ADW&ID56009"     "ADWords&ID53389"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been wondering this ever since I started using MS's control templates examples as
Not long ago I decided to start using Nuget for managing 3rd party libraries.
I don't know if this is possible or not, since I only just started
This is my second post about hibernate. Since I started using hibernate it has
I have had nothing but trouble with Winsock since I started using it. I
Started using Visual Studio 2012 RC since yesterday, We have one WCF solution. Whenever
I just started using Sequel in a really small Sinatra app. Since I've got
I have just started reading about ORMLite since I am interested in using it
I have recently started creating an iPhone application using Appcelerator's Titanium. Since the application
Ever since I started programming this has been something I have been curious about.

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.