text - URL semantic analysis using R -


i have dataset like

url                                                       keywords           impressions     clicks  http://www.thetelegraphandargus.co.uk/sport/sportbcfc     sports|football      5500           456 

i wanted explode data set in following format:

url                                       url keyword         keyword         impressions        clicks  http://www.thetelegraphandargus.co.uk     sport               sports           5500                456  http://www.thetelegraphandargus.co.uk     sportbcfc           football         5500                456 

i have tried splitting them using stringr , urltools libraries.

ee <- as.character(data$url)  eee <- strsplit(ee, "/")  maxlen <- max(sapply(eee, length))  l <-   t(sapply(eee, function(x) c(x, rep(na, maxlen - length(x)))   ))            f=data.frame(l) 

and

 d<-url_parse(as.character(data$url)) 

i able split urls not getting in desired format. being split in same row.

ps: used delimiter function in excel keywords column delimiter "|"

here how csplit splitstackshape package it

csplit(dta1, "keywords", direction = "wide", sep = "|")                                                       a1 keywords   a3  a4 1: http://www.thetelegraphandargus.co.uk/sport/sportbcfc   sports 5500 456 2: http://www.thetelegraphandargus.co.uk/sport/sportbcfc football 5500 456 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -