Omar André Gonzáles Díaz
2015-Oct-24 21:26 UTC
[R] regex not working for some entries in for loop
I'm using some regex in a for loop to check for some values in column "source", and put a result in column "fuente". I need some advice on this topics: -Making the regex parts work, I've tasted them in regexpal.com and they work, but not in R. -Making the code (for loop) more efficient, more clear to read. Cases: - "buy-cheap-online.info", regex: ".*buy.*". - "guardlink.org", regex: ".*guardlink.*". It is not detected neither. - "googleads.g.doubleclick.net", regex: "googleads[.]g[.]doubleclick[.]net". The data is a txt attached in this email. R Code: for (i in 1:nrow(sesionesxfuente)) { organic <- grepl("start.iminent.com|websearch.com| crawler.com|allmyweb.com",sesionesxfuente$source[i], ignore.case = T) adwords <- grepl("cpc|ccp",sesionesxfuente$source[i], ignore.case T) referral <- grepl(".*google\\.com\\.pe.*|.*google\\.co\\.ve\\.*| .*google\\.com\\.br.*|.*google\\.com\\.bo\\.*| .*google\\.com\\.ar.*|.*google\\.com.*", sesionesxfuente$source[i], ignore.case = T) spam <- grepl("site.*|.*event.*|.*free.*|.*theguardlan.*| .*guardlink.*|.*torture.*|.*forum.*| .*buy.*|.*share.*|.*buttons.*| .*pyme\\.lavoztx\\.com\\.*|.*amezon.*| computrabajo.com.pe|.*porn.*|quality", sesionesxfuente$source[i], ignore.case = T) adsense <- grepl("tpc.googlesyndication.com| googleads[.]g[.]doubleclick[.]net",sesionesxfuente$source[i], ignore.case = T) redes.sociales <- grepl("facebook.com| twitter.com",sesionesxfuente$source[i], ignore.case = T) if (sesionesxfuente$source[i] == "(direct)") { sesionesxfuente$fuente[i] <- "directo" } else if (sesionesxfuente$medium[i] == "organic" | organic) { sesionesxfuente$fuente[i] <- "organico" } else if (sesionesxfuente$source[i] == "google" & adwords) { sesionesxfuente$fuente[i] <- "adwords" } else if (referral) { sesionesxfuente$fuente[i] <- "referencias" } else if (adsense) { sesionesxfuente$fuente[i] <- "adsense" } else if (redes.sociales) { sesionesxfuente$fuente[i] <- "redes sociales" } else if (spam) { sesionesxfuente$fuente[i] <- "spam" } else { sesionesxfuente$fuente[i] <- sesionesxfuente$fuente[i] } } Thanks. -------------- next part -------------- structure(list(date = structure(c(1404450000, 1404536400, 1404709200, 1404795600, 1404882000, 1404882000, 1405054800, 1405141200, 1405227600, 1405659600, 1405659600, 1405832400, 1406091600, 1406178000, 1406264400, 1406350800, 1406696400, 1407301200, 1408251600, 1408424400, 1409029200, 1409029200, 1409115600, 1409202000, 1410152400, 1410757200, 1411016400, 1411275600, 1411362000, 1411448400, 1411621200, 1411621200, 1411794000, 1411880400, 1411966800, 1411966800, 1411966800, 1412053200, 1412053200, 1412053200, 1412139600, 1412312400, 1412398800, 1412398800, 1412485200, 1412571600, 1412571600, 1412658000, 1412658000, 1412744400, 1412830800, 1412830800, 1413003600, 1413176400, 1413262800, 1413262800, 1413349200, 1413349200, 1413435600, 1413522000, 1413522000, 1413608400, 1413867600, 1414040400, 1414126800, 1414213200, 1414213200, 1414386000, 1414472400, 1414472400, 1414645200, 1414645200, 1414731600, 1414818000, 1414818000, 1414990800, 1415163600, 1415250000, 1415941200, 1416286800, 1416373200, 1416718800, 1417237200, 1417496400, 1417582800, 1417669200, 1418101200, 1418101200, 1418187600, 1418360400, 1418360400, 1418360400, 1418533200, 1418619600, 1418706000, 1418792400, 1418965200, 1419138000, 1419310800, 1419397200, 1419483600, 1419570000, 1419656400, 1419742800, 1419829200, 1419829200, 1419829200, 1419915600, 1420002000, 1420002000, 1420088400, 1420088400, 1420088400, 1420174800, 1420174800, 1420261200, 1420347600, 1420434000, 1420434000, 1420520400, 1420606800, 1420693200, 1420779600, 1420866000, 1420866000, 1421038800, 1421125200, 1421211600, 1421298000, 1421298000, 1421384400, 1421557200, 1421643600, 1421730000, 1421816400, 1421902800, 1421902800, 1422248400, 1422248400, 1422248400, 1422334800, 1422334800, 1422507600, 1422507600, 1422853200, 1422939600, 1422939600, 1423285200, 1423717200, 1423803600, 1423890000, 1424062800, 1424062800, 1424149200, 1424408400, 1424667600, 1424754000, 1424754000, 1424926800, 1425099600, 1425272400, 1425358800, 1425445200, 1425618000, 1425618000, 1425704400, 1425790800, 1425877200, 1425963600, 1426050000, 1426136400, 1426222800, 1426309200, 1426395600, 1426395600, 1426395600, 1426482000, 1426568400, 1426568400, 1426654800, 1426741200, 1426741200, 1426914000, 1427173200, 1427173200, 1427173200, 1427173200, 1427346000, 1427346000, 1427432400, 1427691600, 1427691600, 1427778000, 1427778000, 1427864400, 1427864400, 1427950800, 1427950800, 1427950800, 1428123600, 1428296400, 1428296400, 1428382800, 1428382800, 1428382800, 1428469200, 1428555600, 1428642000, 1428728400, 1428728400, 1428728400, 1428987600, 1429074000, 1429074000, 1429160400, 1429160400, 1429160400, 1429246800, 1429246800, 1429246800, 1429246800, 1429333200, 1429333200, 1429419600, 1429506000, 1429506000, 1429592400, 1429592400, 1429592400, 1429592400, 1429592400, 1429765200, 1429765200, 1429851600, 1429938000, 1429938000, 1430024400, 1430024400, 1430110800, 1430197200, 1430197200, 1430197200, 1430197200, 1430197200, 1430283600, 1430283600, 1430370000, 1430370000, 1430456400, 1430456400, 1430456400, 1430456400, 1430542800, 1430629200, 1430715600, 1430715600, 1430715600, 1430715600, 1430802000, 1430802000, 1430802000, 1430802000, 1430888400, 1430888400, 1430888400, 1430974800, 1430974800, 1430974800, 1430974800, 1431061200, 1431061200, 1431061200, 1431061200, 1431147600, 1431147600, 1431147600, 1431234000, 1431234000, 1431234000, 1431234000, 1431320400, 1431320400, 1431320400, 1431320400, 1431406800, 1431406800, 1431406800, 1431406800, 1431406800, 1431493200, 1431493200, 1431493200, 1431579600, 1431579600, 1431579600, 1431579600, 1431579600, 1431666000, 1431666000, 1431752400, 1431752400, 1431752400, 1431752400, 1431838800, 1431838800, 1431838800, 1431838800, 1431838800, 1431925200, 1431925200, 1432011600, 1432011600, 1432011600, 1432098000, 1432098000, 1432098000, 1432184400, 1432184400, 1432184400, 1432270800, 1432530000, 1432616400, 1432616400, 1432616400, 1432702800, 1432702800, 1432789200, 1432875600, 1432875600, 1432962000, 1433134800, 1433221200, 1433307600, 1433307600, 1433394000, 1433480400, 1433566800, 1433653200, 1433739600, 1433826000, 1433912400, 1433912400, 1433998800, 1433998800, 1433998800, 1434085200, 1434085200, 1434085200, 1434171600, 1434171600, 1434171600, 1434258000, 1434258000, 1434344400, 1434430800, 1434430800, 1434517200, 1434517200, 1434603600, 1434603600, 1434690000, 1434690000, 1434690000, 1434776400, 1434776400, 1434776400, 1434776400, 1434862800, 1434949200, 1435035600, 1435035600, 1435035600, 1435122000, 1435122000, 1435122000, 1435122000, 1435208400, 1435208400, 1435294800, 1435381200, 1435381200, 1435467600, 1435554000, 1435554000, 1435554000, 1435640400, 1435640400, 1435726800, 1435726800, 1435726800, 1435813200, 1435813200, 1435899600, 1435986000, 1435986000, 1436072400, 1436072400, 1436072400, 1436158800, 1436158800, 1436158800, 1436245200, 1436245200, 1436245200, 1436245200, 1436331600, 1436331600, 1436331600, 1436331600, 1436331600, 1436418000, 1436418000, 1436504400, 1436590800, 1436590800, 1436677200, 1436677200, 1436677200, 1436763600, 1436763600, 1436763600, 1436850000, 1436850000, 1436850000, 1436936400, 1437022800, 1437022800, 1437022800, 1437022800, 1437109200, 1437109200, 1437109200, 1437195600, 1437195600, 1437282000, 1437282000, 1437282000, 1437368400, 1437368400, 1437454800, 1437454800, 1437541200, 1437541200, 1437541200, 1437627600, 1437627600, 1437627600, 1437714000, 1437714000, 1437714000, 1437714000, 1437800400, 1437800400, 1437800400, 1437800400, 1437800400, 1437886800, 1437973200, 1437973200, 1438059600, 1438059600, 1438059600, 1438059600, 1438232400, 1438318800, 1438405200, 1438405200, 1438491600, 1438578000, 1438578000, 1438664400, 1438664400, 1438664400, 1438750800, 1438750800, 1438750800, 1438750800, 1438837200, 1438923600, 1438923600, 1439010000, 1439096400, 1439096400, 1439182800, 1439182800, 1439269200, 1439269200, 1439355600, 1439355600, 1439355600, 1439442000, 1439442000, 1439442000, 1439528400, 1439528400, 1439614800, 1439614800, 1439701200, 1439787600, 1439787600, 1439787600, 1439874000, 1439960400, 1439960400, 1440046800, 1440046800, 1440133200, 1440133200, 1440219600, 1440306000, 1440392400, 1440478800, 1440565200, 1440565200, 1440651600, 1440651600, 1440651600, 1440738000, 1440824400, 1440910800, 1440910800, 1440997200, 1441083600, 1441083600, 1441083600, 1441170000, 1441170000, 1441256400, 1441256400, 1441256400, 1441342800, 1441342800, 1441429200, 1441429200, 1441429200, 1441429200, 1441515600, 1441515600, 1441515600, 1441602000, 1441688400, 1441688400, 1441688400, 1441774800, 1441774800, 1441861200, 1441861200, 1441947600, 1441947600, 1442034000, 1442120400, 1442206800, 1442293200, 1442379600, 1442379600, 1442466000, 1442466000, 1442552400, 1442552400, 1442638800, 1442725200, 1442811600, 1442811600, 1442898000, 1442898000, 1442898000, 1442984400, 1443070800, 1443070800, 1443157200, 1443157200, 1443243600, 1443243600, 1443330000, 1443330000, 1443330000, 1443416400, 1443502800, 1443502800, 1443502800, 1443502800, 1443589200, 1443589200, 1443675600, 1443762000, 1443848400, 1443848400, 1443934800, 1443934800, 1444021200, 1444021200, 1444107600, 1444194000, 1444280400, 1444280400, 1444366800, 1444453200, 1444539600, 1444539600, 1444626000, 1444712400, 1444712400, 1444798800, 1444798800, 1444885200, 1444971600, 1445058000, 1445144400, 1445230800, 1445317200, 1445317200, 1445403600, 1445490000, 1445490000, 1445576400, 1445662800, 1445662800), class = c("POSIXct", "POSIXt"), tzone = "America/Lima"), source = c("(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "google", "(direct)", "(direct)", "(direct)", "(direct)", "google", "bing", "(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "google.com.pe", "google", "google.com.ar", "(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "(direct)", "google", "google", "yahoo", "(direct)", "google", "start.iminent.com", "(direct)", "computrabajo.com.pe", "google", "(direct)", "(direct)", "(direct)", "google", "(direct)", "(direct)", "google", "(direct)", "google", "(direct)", "(direct)", "google", "(direct)", "(direct)", "(direct)", "google", "(direct)", "google", "google", "(direct)", "google", "(direct)", "google.com.pe", "(direct)", "(direct)", "(direct)", "google", "google", "(direct)", "google", "(direct)", "google", "google", "(direct)", "google", "google", "google", "google", "google", "google", "google", "(direct)", "google", "(direct)", "google", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "google", "google", "(direct)", "forum.topic52266738.darodar.com", "google", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "google", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "(direct)", "forum.topic52266738.darodar.com", "google", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "google", "(direct)", "forum.topic52266738.darodar.com", "google", "forum.topic52266738.darodar.com", "google", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "(direct)", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "forum.topic52266738.darodar.com", "(direct)", "forum.topic52266738.darodar.com", "google", "google", "google", "forum.topic52266738.darodar.com", "google", "forum.topic52266738.darodar.com", "(direct)", "google", "google", "(direct)", "(direct)", "google", "(direct)", "google", "yahoo", "forum.topic52266738.darodar.com", "google", "(direct)", "google", "google", "google", "google.com.pe", "google", "google", "google", "(direct)", "google", "localhost:8080", "(direct)", "google", "google", "(direct)", "google", "(direct)", "google", "google", "google", "google", "(direct)", "google", "google.com.ar", "google", "google", "google", "google", "google", "google", "google", "forum.topic52266738.darodar.com", "google", "simple-share-buttons.com", "(direct)", "(direct)", "google", "site38.simple-share-buttons.com", "google", "site40.simple-share-buttons.com", "(direct)", "(direct)", "google", "simple-share-buttons.com", "site17.simple-share-buttons.com", "editors.choice52266738.hulfingtonpost.com", "site12.simple-share-buttons.com", "google", "google", "simple-share-buttons.com", "(direct)", "site20.simple-share-buttons.com", "google", "site33.simple-share-buttons.com", "google", "simple-share-buttons.com", "site30.simple-share-buttons.com", "google", "(direct)", "google", "(direct)", "google", "yahoo", "google", "google", "google", "(direct)", "google", "googlsucks.com", "www.Get-Free-Traffic-Now.com", "buy-cheap-online.info", "google", "(direct)", "depositfiles-porn.ga", "google", "(direct)", "google", "torture.ml", "www.Get-Free-Traffic-Now.com", "buy-cheap-online.info", "torture.ml", "torture.ml", "free-share-buttons.com", "torture.ml", "(direct)", "free-share-buttons.com", "google", "theguardlan.com", "www.Get-Free-Traffic-Now.com", "google", "www.Get-Free-Traffic-Now.com", "free-share-buttons.com", "free-share-buttons.com", "www.Get-Free-Traffic-Now.com", "free-share-buttons.com", "www.Get-Free-Traffic-Now.com", "buy-cheap-online.info", "(direct)", "buy-cheap-online.info", "free-share-buttons.com", "torture.ml", "www.Get-Free-Traffic-Now.com", "google", "www.Get-Free-Traffic-Now.com", "(direct)", "site3.free-share-buttons.com", "(direct)", "google.com.br", "site4.free-share-buttons.com", "www.Get-Free-Traffic-Now.com", "torture.ml", "www.Get-Free-Traffic-Now.com", "(direct)", "google", "site3.free-share-buttons.com", "site4.free-share-buttons.com", "(direct)", "google", "site4.free-share-buttons.com", "www.event-tracking.com", "(direct)", "site3.free-share-buttons.com", "www.event-tracking.com", "(direct)", "google", "site4.free-share-buttons.com", "www.Get-Free-Traffic-Now.com", "(direct)", "guardlink.org", "site3.free-share-buttons.com", "www.event-tracking.com", "(direct)", "google", "www.event-tracking.com", "(direct)", "site4.free-share-buttons.com", "site6.free-share-buttons.com", "www.event-tracking.com", "(direct)", "google", "site6.free-share-buttons.com", "www.event-tracking.com", "(direct)", "google", "site5.free-share-buttons.com", "site6.free-share-buttons.com", "www.event-tracking.com", "(direct)", "free-social-buttons.com", "google", "(direct)", "free-social-buttons.com", "google", "www.Get-Free-Traffic-Now.com", "www.event-tracking.com", "(direct)", "www.event-tracking.com", "(direct)", "free-social-buttons.com", "google", "www.Get-Free-Traffic-Now.com", "(direct)", "free-social-buttons.com", "google", "guardlink.org", "www.event-tracking.com", "www.Get-Free-Traffic-Now.com", "www.event-tracking.com", "(direct)", "free-social-buttons.com", "www.Get-Free-Traffic-Now.com", "(direct)", "free-social-buttons.com", "www.event-tracking.com", "(direct)", "free-social-buttons.com", "google", "www.event-tracking.com", "google", "(direct)", "google", "www.event-tracking.com", "google", "www.event-tracking.com", "google", "(direct)", "www.event-tracking.com", "google", "www.event-tracking.com", "guardlink.org", "google", "www.event-tracking.com", "www.event-tracking.com", "google", "google", "google", "google", "google", "(direct)", "google", "google", "lima-lima.olx.com.pe", "www.event-tracking.com", "google", "lima.quebarato.com.pe", "www.event-tracking.com", "google", "google.com.ar", "www.event-tracking.com", "google", "yahoo", "google", "(direct)", "google", "google", "www.event-tracking.com", "(direct)", "google", "(direct)", "google", "www.event-tracking.com", "(direct)", "google", "google.com", "www.event-tracking.com", "google", "google", "(direct)", "google", "google.com", "google", "google.co.ve", "google.com", "www.event-tracking.com", "google", "www.event-tracking.com", "google", "google", "www.event-tracking.com", "(direct)", "google", "googleads.g.doubleclick.net", "www.event-tracking.com", "(direct)", "google", "gg.net.ru", "google", "www.event-tracking.com", "google", "www.event-tracking.com", "(direct)", "google", "www.event-tracking.com", "(direct)", "google", "www.event-tracking.com", "(direct)", "google", "www.event-tracking.com", "(direct)", "google", "google.com", "www.event-tracking.com", "google", "google.co.ve", "google.com", "google.com.bo", "www.event-tracking.com", "(direct)", "google", "google", "google", "www.event-tracking.com", "google", "tpc.googlesyndication.com", "www.event-tracking.com", "google", "google.com", "www.event-tracking.com", "(direct)", "google", "google.com", "google", "google", "openurls.com.cn", "tradesou.com", "www.event-tracking.com", "(direct)", "google", "google.com", "(direct)", "google", "(direct)", "google", "www.event-tracking.com", "google", "www.event-tracking.com", "(direct)", "google", "(direct)", "google", "www.event-tracking.com", "(direct)", "google", "www.event-tracking.com", "(direct)", "google", "google.com", "www.event-tracking.com", "(direct)", "erot.co", "google", "quirktools.com", "www.event-tracking.com", "google", "google", "www.event-tracking.com", "(direct)", "google", "pyme.lavoztx.com", "www.event-tracking.com", "google", "google", "(direct)", "google", "google", "(direct)", "google", "(direct)", "chinese-amezon.com", "google", "(direct)", "google", "google.com", "googleads.g.doubleclick.net", "google", "(direct)", "google", "google", "(direct)", "google", "(direct)", "google", "(direct)", "google", "(direct)", "google", "google.com", "(direct)", "google", "hongfanji.com", "(direct)", "google", "(direct)", "google", "google", "(direct)", "ehowenespanol.com", "google", "google", "(direct)", "google", "(direct)", "google", "(direct)", "google", "google", "google", "google", "google", "google", "google.com.mx", "(direct)", "google", "googleads.g.doubleclick.net", "google", "google", "(direct)", "google", "google", "(direct)", "google", "qualitymarketzone.com", "google", "qualitymarketzone.com", "(direct)", "google", "qualitymarketzone.com", "google", "qualitymarketzone.com", "(direct)", "google", "google.com", "qualitymarketzone.com", "google", "googleads.g.doubleclick.net", "qualitymarketzone.com", "google", "(direct)", "google", "qualitymarketzone.com", "bing", "google", "(direct)", "google", "(direct)", "google", "google", "google", "google", "google", "google", "googleads.g.doubleclick.net", "(direct)", "google", "(direct)", "google", "google", "google", "(direct)", "google", "(direct)", "google", "google.com", "google", "google", "rednise.com", "(direct)", "google", "(direct)", "google", "(direct)", "google", "google.com", "google", "(direct)", "facebook.com", "google", "google.com", "(direct)", "google", "google", "google", "(direct)", "google", "(direct)", "google", "(direct)", "google", "google", "google", "(direct)", "google", "google", "google", "(direct)", "google", "google", "(direct)", "google", "google", "yahoo", "google", "google", "google", "google", "google", "(direct)", "google", "google", "(direct)", "google", "google", "facebook.com", "google"), medium = c("(none)", "(none)", "(none)", "(none)", "(none)", "organic", "(none)", "(none)", "(none)", "(none)", "organic", "organic", "(none)", "(none)", "(none)", "(none)", "(none)", "(none)", "(none)", "(none)", "(none)", "referral", "organic", "referral", "(none)", "(none)", "(none)", "(none)", "(none)", "(none)", "(none)", "organic", "organic", "organic", "(none)", "organic", "referral", "(none)", "referral", "organic", "(none)", "(none)", "(none)", "organic", "(none)", "(none)", "organic", "(none)", "organic", "(none)", "(none)", "organic", "(none)", "(none)", "(none)", "organic", "(none)", "organic", "organic", "(none)", "organic", "(none)", "referral", "(none)", "(none)", "(none)", "organic", "organic", "(none)", "organic", "(none)", "organic", "organic", "(none)", "organic", "organic", "organic", "organic", "organic", "organic", "organic", "(none)", "organic", "(none)", "organic", "referral", "referral", "organic", "organic", "(none)", "referral", "organic", "referral", "referral", "referral", "organic", "referral", "referral", "referral", "referral", "referral", "referral", "referral", "referral", "(none)", "referral", "organic", "referral", "referral", "organic", "(none)", "referral", "organic", "referral", "organic", "referral", "referral", "(none)", "referral", "referral", "referral", "referral", "referral", "(none)", "referral", "organic", "organic", "organic", "referral", "organic", "referral", "(none)", "organic", "organic", "(none)", "(none)", "organic", "(none)", "organic", "organic", "referral", "organic", "(none)", "organic", "organic", "organic", "referral", "organic", "organic", "organic", "(none)", "organic", "referral", "(none)", "organic", "organic", "(none)", "organic", "(none)", "organic", "organic", "organic", "organic", "(none)", "organic", "referral", "organic", "organic", "organic", "organic", "organic", "organic", "organic", "referral", "organic", "referral", "(none)", "(none)", "organic", "referral", "organic", "referral", "(none)", "(none)", "organic", "referral", "referral", "referral", "referral", "organic", "organic", "referral", "(none)", "referral", "organic", "referral", "organic", "referral", "referral", "organic", "(none)", "organic", "(none)", "organic", "organic", "organic", "organic", "organic", "(none)", "organic", "referral", "referral", "referral", "organic", "(none)", "referral", "organic", "(none)", "organic", "referral", "referral", "referral", "referral", "referral", "referral", "referral", "(none)", "referral", "organic", "referral", "referral", "organic", "referral", "referral", "referral", "referral", "referral", "referral", "referral", "(none)", "referral", "referral", "referral", "referral", "organic", "referral", "(none)", "referral", "(none)", "referral", "referral", "referral", "referral", "referral", "(none)", "organic", "referral", "referral", "(none)", "organic", "referral", "referral", "(none)", "referral", "referral", "(none)", "organic", "referral", "referral", "(none)", "referral", "referral", "referral", "(none)", "organic", "referral", "(none)", "referral", "referral", "referral", "(none)", "organic", "referral", "referral", "(none)", "organic", "referral", "referral", "referral", "(none)", "referral", "organic", "(none)", "referral", "organic", "referral", "referral", "(none)", "referral", "(none)", "referral", "organic", "referral", "(none)", "referral", "organic", "referral", "referral", "referral", "referral", "(none)", "referral", "referral", "(none)", "referral", "referral", "(none)", "referral", "organic", "referral", "organic", "(none)", "organic", "referral", "organic", "referral", "organic", "(none)", "referral", "organic", "referral", "referral", "organic", "referral", "referral", "organic", "organic", "organic", "organic", "organic", "(none)", "organic", "organic", "referral", "referral", "organic", "referral", "referral", "organic", "referral", "referral", "organic", "organic", "organic", "(none)", "organic", "organic", "referral", "(none)", "organic", "(none)", "organic", "referral", "(none)", "organic", "referral", "referral", "organic", "organic", "(none)", "organic", "referral", "organic", "referral", "referral", "referral", "organic", "referral", "organic", "organic", "referral", "(none)", "organic", "referral", "referral", "(none)", "organic", "referral", "organic", "referral", "organic", "referral", "(none)", "organic", "referral", "(none)", "organic", "referral", "(none)", "organic", "referral", "(none)", "organic", "referral", "referral", "organic", "referral", "referral", "referral", "referral", "(none)", "organic", "organic", "organic", "referral", "organic", "referral", "referral", "organic", "referral", "referral", "(none)", "organic", "referral", "organic", "organic", "referral", "referral", "referral", "(none)", "organic", "referral", "(none)", "organic", "(none)", "organic", "referral", "organic", "referral", "(none)", "organic", "(none)", "organic", "referral", "(none)", "organic", "referral", "(none)", "organic", "referral", "referral", "(none)", "referral", "organic", "referral", "referral", "organic", "organic", "referral", "(none)", "organic", "referral", "referral", "organic", "organic", "(none)", "organic", "organic", "(none)", "organic", "(none)", "referral", "organic", "(none)", "organic", "referral", "referral", "organic", "(none)", "organic", "organic", "(none)", "organic", "(none)", "organic", "(none)", "organic", "(none)", "organic", "referral", "(none)", "organic", "referral", "(none)", "organic", "(none)", "organic", "organic", "(none)", "referral", "organic", "organic", "(none)", "organic", "(none)", "organic", "(none)", "organic", "organic", "organic", "organic", "organic", "organic", "referral", "(none)", "organic", "referral", "organic", "organic", "(none)", "organic", "organic", "(none)", "organic", "referral", "organic", "referral", "(none)", "organic", "referral", "organic", "referral", "(none)", "organic", "referral", "referral", "organic", "referral", "referral", "organic", "(none)", "organic", "referral", "organic", "organic", "(none)", "organic", "(none)", "organic", "organic", "organic", "organic", "organic", "organic", "referral", "(none)", "organic", "(none)", "organic", "organic", "organic", "(none)", "organic", "(none)", "organic", "referral", "organic", "organic", "referral", "(none)", "organic", "(none)", "organic", "(none)", "organic", "referral", "organic", "(none)", "referral", "organic", "referral", "(none)", "organic", "organic", "organic", "(none)", "organic", "(none)", "organic", "(none)", "organic", "organic", "organic", "(none)", "organic", "organic", "organic", "(none)", "organic", "organic", "(none)", "organic", "organic", "organic", "organic", "organic", "organic", "organic", "organic", "(none)", "organic", "organic", "(none)", "organic", "organic", "referral", "organic"), users = c(3L, 1L, 1L, 2L, 4L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 14L, 1L, 1L, 7L, 1L, 2L, 6L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 5L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 3L, 1L, 1L, 3L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L,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, 3L, 1L, 1L, 6L, 2L, 3L, 1L, 4L, 1L, 6L, 3L, 1L, 6L, 1L, 1L, 5L, 5L, 6L, 1L, 2L, 1L, 8L, 2L, 10L, 5L, 3L, 1L, 4L, 4L, 5L, 2L, 2L, 8L, 1L, 7L, 3L, 1L, 8L, 8L, 4L, 4L, 5L, 1L, 8L, 4L, 1L, 8L, 5L, 1L, 1L), fuente = c("directo", "directo", "directo", "directo", "directo", "organico", "directo", "directo", "directo", "directo", "organico", "organico", "directo", "directo", "directo", "directo", "directo", "directo", "directo", "directo", "directo", "referencias", "organico", "referencias", "directo", "directo", "directo", "directo", "directo", "directo", "directo", "organico", "organico", "organico", "directo", "organico", "organico", "directo", "spam", "organico", "directo", "directo", "directo", "organico", "directo", "directo", "organico", "directo", "organico", "directo", "directo", "organico", "directo", "directo", "directo", "organico", "directo", "organico", "organico", "directo", "organico", "directo", "referencias", "directo", "directo", "directo", "organico", "organico", "directo", "organico", "directo", "organico", "organico", "directo", "organico", "organico", "organico", "organico", "organico", "organico", "organico", "directo", "organico", "directo", "organico", "spam", "spam", "organico", "organico", "directo", "spam", "organico", "spam", "spam", "spam", "organico", "spam", "spam", "spam", "spam", "spam", "spam", "spam", "spam", "directo", "spam", "organico", "spam", "spam", "organico", "directo", "spam", "organico", "spam", "organico", "spam", "spam", "directo", "spam", "spam", "spam", "spam", "spam", "directo", "spam", "organico", "organico", "organico", "spam", "organico", "spam", "directo", "organico", "organico", "directo", "directo", "organico", "directo", "organico", "organico", "spam", "organico", "directo", "organico", "organico", "organico", "referencias", "organico", "organico", "organico", "directo", "organico", NA, "directo", "organico", "organico", "directo", "organico", "directo", "organico", "organico", "organico", "organico", "directo", "organico", "referencias", "organico", "organico", "organico", "organico", "organico", "organico", "organico", "spam", "organico", "spam", "directo", "directo", "organico", "spam", "organico", "spam", "directo", "directo", "organico", "spam", "spam", NA, "spam", "organico", "organico", "spam", "directo", "spam", "organico", "spam", "organico", "spam", "spam", "organico", "directo", "organico", "directo", "organico", "organico", "organico", "organico", "organico", "directo", "organico", NA, "spam", NA, "organico", "directo", "spam", "organico", "directo", "organico", "spam", "spam", NA, "spam", "spam", "spam", "spam", "directo", "spam", "organico", "spam", "spam", "organico", "spam", "spam", "spam", "spam", "spam", "spam", NA, "directo", NA, "spam", "spam", "spam", "organico", "spam", "directo", "spam", "directo", "referencias", "spam", "spam", "spam", "spam", "directo", "organico", "spam", "spam", "directo", "organico", "spam", "spam", "directo", "spam", "spam", "directo", "organico", "spam", "spam", "directo", NA, "spam", "spam", "directo", "organico", "spam", "directo", "spam", "spam", "spam", "directo", "organico", "spam", "spam", "directo", "organico", "spam", "spam", "spam", "directo", "spam", "organico", "directo", "spam", "organico", "spam", "spam", "directo", "spam", "directo", "spam", "organico", "spam", "directo", "spam", "organico", NA, "spam", "spam", "spam", "directo", "spam", "spam", "directo", "spam", "spam", "directo", "spam", "organico", "spam", "organico", "directo", "organico", "spam", "organico", "spam", "organico", "directo", "spam", "organico", "spam", NA, "organico", "spam", "spam", "organico", "organico", "organico", "organico", "organico", "directo", "organico", "organico", NA, "spam", "organico", NA, "spam", "organico", "referencias", "spam", "organico", "organico", "organico", "directo", "organico", "organico", "spam", "directo", "organico", "directo", "organico", "spam", "directo", "organico", "referencias", "spam", "organico", "organico", "directo", "organico", "referencias", "organico", "referencias", "referencias", "spam", "organico", "spam", "organico", "organico", "spam", "directo", "organico", NA, "spam", "directo", "organico", NA, "organico", "spam", "organico", "spam", "directo", "organico", "spam", "directo", "organico", "spam", "directo", "organico", "spam", "directo", "organico", "referencias", "spam", "organico", "referencias", "referencias", "referencias", "spam", "directo", "organico", "organico", "organico", "spam", "organico", "adsense", "spam", "organico", "referencias", "spam", "directo", "organico", "referencias", "organico", "organico", NA, NA, "spam", "directo", "organico", "referencias", "directo", "organico", "directo", "organico", "spam", "organico", "spam", "directo", "organico", "directo", "organico", "spam", "directo", "organico", "spam", "directo", "organico", "referencias", "spam", "directo", NA, "organico", NA, "spam", "organico", "organico", "spam", "directo", "organico", NA, "spam", "organico", "organico", "directo", "organico", "organico", "directo", "organico", "directo", "spam", "organico", "directo", "organico", "referencias", NA, "organico", "directo", "organico", "organico", "directo", "organico", "directo", "organico", "directo", "organico", "directo", "organico", "referencias", "directo", "organico", NA, "directo", "organico", "directo", "organico", "organico", "directo", NA, "organico", "organico", "directo", "organico", "directo", "organico", "directo", "organico", "organico", "organico", "organico", "organico", "organico", "referencias", "directo", "organico", NA, "organico", "organico", "directo", "organico", "organico", "directo", "organico", "spam", "organico", "spam", "directo", "organico", "spam", "organico", "spam", "directo", "organico", "referencias", "spam", "organico", NA, "spam", "organico", "directo", "organico", "spam", "organico", "organico", "directo", "organico", "directo", "organico", "organico", "organico", "organico", "organico", "organico", NA, "directo", "organico", "directo", "organico", "organico", "organico", "directo", "organico", "directo", "organico", "referencias", "organico", "organico", NA, "directo", "organico", "directo", "organico", "directo", "organico", "referencias", "organico", "directo", "redes sociales", "organico", "referencias", "directo", "organico", "organico", "organico", "directo", "organico", "directo", "organico", "directo", "organico", "organico", "organico", "directo", "organico", "organico", "organico", "directo", "organico", "organico", "directo", "organico", "organico", "organico", "organico", "organico", "organico", "organico", "organico", "directo", "organico", "organico", "directo", "organico", "organico", "redes sociales", "organico")), .Names = c("date", "source", "medium", "users", "sessions", "fuente"), row.names = c(NA, -617L), profile.info = structure(list(profile.id = "88090999", account.id = "52266738", webproperty.id = "UA-52266738-1", internal.webproperty.id = "84690154", profile.name = "Chayan Web Official", table.id = "ga:88090999"), .Names = c("profile.id", "account.id", "webproperty.id", "internal.webproperty.id", "profile.name", "table.id")), query = structure(list(start.date = "2014-07-04", end.date = "today", profile.id = "ga:88090999", dimensions = "ga:date,ga:source,ga:medium", metrics = "ga:users,ga:sessions", start.index = 1L, max.results = 10000L), .Names = c("start.date", "end.date", "profile.id", "dimensions", "metrics", "start.index", "max.results")), class = "data.frame")
> From: Omar Andr? Gonz?les D?az > Subject: [R] regex not working for some entries in for loop > > I'm using some regex in a for loop to check for some values in column "source", > and put a result in column "fuente".Your regexes are on multiple lines and include whitespace and linefeeds. For example you are not testing for " .*forum.*|.*buy.*"; you are testing for " .*forum.*| .*buy.*" (which among other things includes a \n) Don?t do that. Keep it to one line with no white space. if you must have line breaks in the code, form the pattern using paste, as in pat1 <- paste(c("site.*", ".*event.*", ".*free.*", ".*theguardlan.*", ".*guardlink.*", ".*torture.*", ".*forum.*", ".*buy.*", ".*share.*", ".*buttons.*", ".*pyme\\.lavoztx\\.com\\.*", ".*amezon.*", "computrabajo.com.pe", ".*porn.*", "quality"), collapse="|") spam <- grepl(pat1, sf$source,ignore.case = T) Also, it's not immediately clear why you?re looping. grepl returns a vector of logicals; you have a vector of character strings. Consider replacing 'if' constructs with 'ifelse' - albeit a complicated ifelse() - and doing the whole thing without a loop. S Ellison ******************************************************************* This email and any attachments are confidential. Any use, copying or disclosure other than by the intended recipient is unauthorised. If you have received this message in error, please notify the sender immediately via +44(0)20 8943 7000 or notify postmaster at lgcgroup.com and delete this message and any copies from your computer and network. LGC Limited. Registered in England 2991879. Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
Omar André Gonzáles Díaz
2015-Nov-08 04:42 UTC
[R] regex not working for some entries in for loop
Thanks S. Ellison. Finally, Ihad some time to test it. Thanks for your clarification. Just one more question: You say: Your regexes are on multiple lines and include whitespace and linefeeds. For example you are not testing for " .*forum.*|.*buy.*"; you are testing for " .*forum.*| .*buy.*" But, the ".*", as far as I understand, means: any character, 0 or more times. So I should cover the blank and break lines. May you explain this further, this is not making click on my head. 2015-10-26 7:29 GMT-05:00 S Ellison <S.Ellison at lgcgroup.com>:> > > > From: Omar Andr? Gonz?les D?az > > Subject: [R] regex not working for some entries in for loop > > > > I'm using some regex in a for loop to check for some values in column > "source", > > and put a result in column "fuente". > > Your regexes are on multiple lines and include whitespace and linefeeds. > For example you are not testing for > " .*forum.*|.*buy.*"; you are testing for > " .*forum.*| > .*buy.*" > (which among other things includes a \n) > Don?t do that. Keep it to one line with no white space. > if you must have line breaks in the code, form the pattern using paste, as > in > pat1 <- paste(c("site.*", ".*event.*", ".*free.*", ".*theguardlan.*", > ".*guardlink.*", ".*torture.*", ".*forum.*", ".*buy.*", > ".*share.*", ".*buttons.*", ".*pyme\\.lavoztx\\.com\\.*", > ".*amezon.*", "computrabajo.com.pe", ".*porn.*", "quality"), > collapse="|") > > spam <- grepl(pat1, sf$source,ignore.case = T) > > Also, it's not immediately clear why you?re looping. grepl returns a > vector of logicals; you have a vector of character strings. Consider > replacing 'if' constructs with 'ifelse' - albeit a complicated ifelse() - > and doing the whole thing without a loop. > > S Ellison > > > ******************************************************************* > This email and any attachments are confidential. Any u...{{dropped:17}}